如何修复布局顶部的视图并使布局的其余部分折叠?

问题描述 投票:2回答:1

我想设计一个像吹响应用程序的布局。我想在我的布局上修复VideoView,其余布局表现为collapsing状态。我写这段代码,但我没有得到结果。

   <?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"
    tools:context=".view.DetailMyCourseActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <VideoView
            android:id="@+id/videoView"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_alignParentTop="true"/>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="192dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true"
        android:layout_below="@+id/videoView">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="@android:color/transparent"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true"
            app:titleEnabled="false">
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            <TextView
                android:id="@+id/txtTitleCourse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="15dp"
                android:textSize="30sp"
                android:text="عنوان دوره دروه"/>
            <TextView
                android:id="@+id/txtInstructor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="15dp"
                android:layout_below="@+id/txtTitleCourse"
                android:textSize="20sp"
                android:text="علیرضا عزیزی"/>
            </RelativeLayout>
            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                app:tabIndicatorColor="@android:color/white"
                app:tabSelectedTextColor="@android:color/white"
                app:tabTextColor="#fff"
                app:tabIndicator="@android:color/white"
                app:tabIndicatorHeight="1.5dp"
                app:tabMode="fixed"
                app:tabGravity="fill"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_below="@+id/app_bar_layout">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewpager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/txt_description_course"/>
            </RelativeLayout>
        </android.support.v4.widget.NestedScrollView>
    </RelativeLayout>

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

enter image description here

enter image description here

enter image description here

android xml android-collapsingtoolbarlayout
1个回答
3
投票

这是完整的项目 - github url

或者你可以尝试使用这段代码 -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/tabanim_maincontent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <VideoView
        android:id="@+id/videoview"
        android:layout_width="match_parent"
        android:layout_height="180dp" />

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordiLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/videoview">

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

            <LinearLayout
                app:layout_scrollFlags="scroll|enterAlways|snap"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:orientation="vertical"
                android:background="#ffffff">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Your topics title goes here. "
                    android:textColor="#000000"
                    android:textSize="17dp"
                    android:layout_margin="10dp"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="subtitle goes here "
                    android:textColor="#000000"
                    android:textSize="12dp"
                    android:layout_margin="10dp"/>

            </LinearLayout>

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

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

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

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

</RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.