在屏幕上方具有固定视图的布局,下方具有可折叠视图

时间:2018-08-13 17:09:34

标签: android android-layout android-xml

我正在尝试使用以下格式创建布局:

enter image description here

ViewPager包含一个TabLayout,每个TabLayout包含一个片段,其中包含一个RecyclerView。我还无法创建一个可以正常工作的布局(我尝试过的所有操作都可以滚动红色和蓝色区域,或者它们都保持固定)。这是我当前的布局,它同时滚动了红色和蓝色区域。关于如何实现所需布局的任何想法?

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/fragment_video_appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:fitsSystemWindows="true">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/fragment_video_info_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.v7.widget.AppCompatImageView
                android:id="@+id/fragment_video_imageview"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="fitXY"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@android:color/darker_gray" />

            <TextView
                android:id="@+id/fragment_video_timelength_textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingStart="5dp"
                android:paddingEnd="5dp"
                android:paddingTop="3dp"
                android:paddingBottom="3dp"
                android:textSize="12sp"
                android:textColor="@color/white"
                android:background="@color/dimfilter"
                app:layout_constraintBottom_toBottomOf="@+id/fragment_video_imageview"
                app:layout_constraintEnd_toEndOf="parent"
                tools:text="03:45"/>

        </android.support.constraint.ConstraintLayout>

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/fragment_user_collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|enterAlways"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@color/white">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                app:layout_collapseMode="parallax">

                <TextView
                    android:id="@+id/fragment_video_title_textview"
                    style="@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="8dp"
                    android:ellipsize="end"
                    android:maxLines="1"
                    android:textStyle="bold"
                    tools:text="funny videos" />

                <TextView
                    android:id="@+id/fragment_video_plays_textview"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginEnd="16dp"
                    android:textSize="12sp"
                    tools:text="1.7k plays ⋅ 4 years ago" />

                <TextView
                    android:id="@+id/fragment_video_description_textview"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginTop="10dp"
                    android:textColor="@color/colorPrimaryText"
                    android:textSize="13sp"
                    tools:text="funny videos compilation"/>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginTop="8dp"
                    android:background="@color/mediumLightGray"/>

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginEnd="16dp">

                    <include layout="@layout/item_user" />
                </FrameLayout>
            </LinearLayout>

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/fragment_video_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.design.widget.TabLayout
            android:id="@+id/fragment_video_tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/mediumLightGray"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabTextColor="@color/darkMediumGray"
            app:tabSelectedTextColor="@color/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:layout_collapseMode="pin"/>

    </android.support.v4.view.ViewPager>



    <include layout="@layout/layout_content_progress" />

    <include layout="@layout/layout_message" />

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

1 个答案:

答案 0 :(得分:0)

在这里找到类似的问题和解决方案:https://stackoverflow.com/a/44710307/7648952

我修改过的布局:

DropShadowEffect