gpt4 book ai didi

android - 如何将 View 固定在布局的顶部并折叠布局的其余部分?

转载 作者:搜寻专家 更新时间:2023-11-01 08:18:35 25 4
gpt4 key购买 nike

我想设计一个类似 blew 应用程序的布局。我想在我的布局顶部修复一个 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

最佳答案

这是完整的项目 - 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>

关于android - 如何将 View 固定在布局的顶部并折叠布局的其余部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54849962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com