繁体   English   中英

具有全屏背景图片的CoordinatorLayout

[英]CoordinatorLayout with full screen background image

在此处输入图片说明

我试图通过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>

您应该做的是将another layout设置为background color并在其中设置另一个RelativeLayout 然后include您当前的布局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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM