首页 > 解决方案 > 如何使用 ScrollView 制作这种效果?

问题描述

我有一个ScrollView高度和宽度设置为match_parent. 这ScrollView有一个RelativeLayout内容。当用户滚动屏幕时,它RelativeLayout会覆盖屏幕的顶部。但问题是,在屏幕的这个上部,除了不同的视图外,还有一个close按钮,当它可见时应该是可以点击的,当下面RelativeLayout覆盖它时,它应该是不可点击的。问题是ScrollView不允许单击此按钮。如果我们ScrollView沿 XML 层次结构排列按钮,那么它也会滚动,但我需要顶部视图和此按钮保持静态。这是应该如何的图像。

<carbon.widget.RelativeLayout 
    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:background="@color/cyan"
    tools:context=".OptionsActivity">

    <carbon.widget.Button
        android:id="@+id/close"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:background="@drawable/close"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="60dp"
        android:layout_marginEnd="21dp"
        app:carbon_elevation="0dp" />

    <com.xw.repo.widget.BounceScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:scrollbars="none">

        <carbon.widget.RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="110dp"
            android:fillViewport="true">

        <!-- content -->

        </carbon.widget.RelativeLayout>

    </com.xw.repo.widget.BounceScrollView>

</carbon.widget.RelativeLayout>

标签: javaandroidxmlkotlin

解决方案


CollapsingToolbarLayout我用过NestedScrollView


推荐阅读