滚动时将 ImageView 停靠在屏幕顶部

Dock ImageView on top of screen while scrolling

这是我的布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">

<include
    android:id="@+id/appBar"
    layout="@layout/app_bar" />

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appBar"
    android:layout_centerHorizontal="true">

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

        <ImageView
            android:id="@+id/imageView_CoverImage"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_centerHorizontal="true"
            android:scaleType="fitXY" />

        <ScrollView
            android:id="@+id/scrollView_TextView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal">

            <TextView
                android:id="@+id/textView_Description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#ffffff" />
        </ScrollView>

    </LinearLayout>
</ScrollView>

我在 ScrollView 中有一个 ImageView 和一个 TextView,而 TextView 在另一个 ScrollView 中。 我的问题是, 向上滚动时是否可以将 ImageView 停靠在屏幕顶部(图像底部的 25% 应该对用户可见)和TextView 应该可以滚动以查看其余文本。

我建议你看看支持库中的NestedScrollView

您甚至需要在设计中嵌套两个滚动视图,这似乎有点奇怪。也许你应该考虑制作一个新的片段来保存额外的信息。你真的不应该在一个视图组中拥有太多信息,以至于你被迫嵌套两个滚动视图。

祝你好运!