具有全屏背景图片的CoordinatorLayout

时间:2018-07-05 14:16:30

标签: 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>

1 个答案:

答案 0 :(得分:0)

您应该做的是将another layout设置为background color,然后再添加一个RelativeLayout。然后 include ,将您当前的布局放到该布局中,这样对您来说很容易处理。

  <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>