java - 具有全屏背景图像的 CoordinatorLayout

标签 java android xml android-layout android-coordinatorlayout

enter image description here

我尝试通过 CoordinatorLayout 获得此结果,但无法在背景上设置全屏图像,该图像在整个屏幕上展开,与图像中相同。我尝试了几种方法,例如将 LinearLayout 放入 CollapsingToolbarLayout 中,但没有接近我想要的布局。

我尝试了几种方法来实现这一目标,但没有取得任何进展。请帮助

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:clickable="true"
    android:focusable="true"
    android:fitsSystemWindows="true"
    android:background="?android:attr/colorBackground"
    android:id="@+id/viewuserProfileMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        app:layout_collapseMode="parallax"
                        android:src="@drawable/baby"
                        android:scaleType="centerCrop"
                        app:layout_collapseParallaxMultiplier="0.7"/>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/diagonal_cut_layerlist">

                        <de.hdodenhof.circleimageview.CircleImageView
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:background="@color/primary"
                            />

                    </RelativeLayout>


                </RelativeLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:layout_scrollFlags="scroll|enterAlways">

                </android.support.v7.widget.Toolbar>

            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

    </RelativeLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

    </android.support.v4.widget.NestedScrollView>


</android.support.design.widget.CoordinatorLayout>

最佳答案

您应该做的是让另一个布局设置其背景颜色,并在其中添加另一个RelativeLayout。然后将您当前的布局包含到该布局中,这样您就可以轻松处理。

  <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:clickable="true"
    android:focusable="true"
    android:fitsSystemWindows="true"
     android:background="?android:attr/colorBackground"
    android:id="@+id/viewuserProfileMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp">

        <include layout="@layout/yourCurrentLayout except it's background"/>


    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

关于java - 具有全屏背景图像的 CoordinatorLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51193605/

相关文章:

android - 从 onClickListener 检索图像(保存在 sqlite 中)

android - 自定义对话框在 android 顶部提供空白

.net - 在 Fsharp 中将 XML 文件转换为 CSV 文件

java - 在现有 GUI 中播放 mp4 剪辑

java - 使用 Springboot 和 Quartz 使用自己的 Cron 表达式来调度多个作业

java 深度优先搜索

c# - 根据属性将元素反序列化为属性

java - 提取字符串的设备名称

java - NoClassDefFoundError无法从azure表获取数据

xml - 使用 BaseX GUI 时遇到的问题