gpt4 book ai didi

android - 如何使 nestedscrollview 的 subview 之一变为粘性标题?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:05:15 29 4
gpt4 key购买 nike

下面是我的代码 fragment 。

<?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:id="@+id/coordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
tools:context="com.ajinkyabadve.mywatchlist.movie_detail_new.MovieActivity"> <ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />

<include
android:id="@+id/retryLayoutNoInternet"
layout="@layout/no_internet_retry_layout"
android:visibility="gone" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="400dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

<ImageView
android:id="@+id/poster"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/poster_of_movie"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />

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

</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/content"
layout="@layout/content_movie" />

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="112dp"
android:background="@color/colorPrimary"
android:elevation="4dp"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom"
app:layout_collapseMode="pin"
app:theme="@style/ThemeOverlay.AppCompat.Light">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:minHeight="?android:attr/actionBarSize"
android:orientation="vertical">

<TextView
android:id="@+id/movieTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse" />

<TextView
android:id="@+id/movieOrignalTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="subtitle"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle.Inverse" />
</LinearLayout>
</android.support.v7.widget.Toolbar>

下面是content_movie.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:id="@+id/content_movie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.ajinkyabadve.mywatchlist.movie_detail_new.MovieActivity"
tools:showIn="@layout/activity_movie">

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

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

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

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


<!-- Below tablayout I want to work as a sticky header -->
<!--<android.support.design.widget.TabLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="100dp"-->
<!--android:background="@color/colorPrimary" />--> </LinearLayout>
</android.support.v4.widget.NestedScrollView>

评论的 tablayout 应该作为一个粘性标题(意味着它在滚动时到达顶部时不应该滚动)。如何使用坐标布局实现这种效果?或者以任何其他方式。我们可以使用自定义行为或其他东西?

最佳答案

您可以使用以下库来实现此效果。

https://github.com/emilsjolander/StickyScrollViewItems

这基本上是一个自定义 ScrollView ,在此 ScrollView 中,您可以通过添加标签使任何 subview 或布局具有粘性:

android:tag="sticky"

希望对您有所帮助!

关于android - 如何使 nestedscrollview 的 subview 之一变为粘性标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41281380/

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