【问题标题】:CoordinatorLayout with full screen background image具有全屏背景图像的 CoordinatorLayout
【发布时间】:2018-07-05 14:16:30
【问题描述】:

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

【问题讨论】:

  • 你也想折叠你的布局吗?
  • 是的,也有圆形图像
  • 请检查我的答案并这样做,这样您就可以轻松处理所需布局的多层。

标签: java android xml android-layout android-coordinatorlayout


【解决方案1】:

您应该做的是将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>

【讨论】:

  • 将尽快为您提供结果。感谢 Umair 的帮助
  • 我需要在相对布局中再创建一个 CoordinatorLayout
  • @Ritu 没有必要,但如果您的要求如此,那么您可以做到。但是,如果您在包含的布局文件中创建另一个 CoordinatorLayout 会很好。
  • 我会尝试你的建议,然后告诉你结果。谢谢
  • 确定没问题。
猜你喜欢
  • 2016-12-31
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-22
相关资源
最近更新 更多