Android:仅尝试滚动 TextView 时工具栏会滚动

标签 android

Android:我使用 Material science 创建了一个工具栏,我正在我的 Activity 中使用它。我的 Activity 包含一个 TextView 和 2 个按钮(上一个和下一个)。文本是多行的,所以我使用的是 Scrollview,但问题是通过添加 ScrollView ,当我滚动文本时,我的工具栏也被隐藏了。我理解这一点,因为我将工具栏包含在 ScrollView 中,因此它也会滚动。但我只想滚动我的文本而不是我的工具栏,并希望始终在顶部显示我的工具栏。请查看我的 xml 文件并让我知道解决方案。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <include android:id="@+id/app_bar" layout="@layout/toolbar"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/app_bar"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Singleton"
        android:id="@+id/textView"
        android:layout_marginTop="70dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textColor="#212121"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Next"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="10dp"
        android:background="@color/designPrimaryBackgroundColor"
        android:textColor="#FFFFFF"
        android:onClick="onClick"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/single_string"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

我正在使用添加自定义工具栏。请让我知道如何在此文件中包含工具栏,以便在滚动文本时它不会滚动

最佳答案

您应该有一个 LinearLayout 作为主要的父级,并且有工具栏(包括)作为第一个子级和 ScrollView 作为第二个子级

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation:vertical >

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

    <ScrollView android:layout_width="match_parent"
        android:layout_height="match_parent" >
        ...

关于Android:仅尝试滚动 TextView 时工具栏会滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29066473/

相关文章:

java - 我如何知道 AsyncTask 后台线程何时完成?

android - 在协调器布局中单击 FAB(FloatingActionButton) 时,AppBarLayout View 变为空白

java - 永不关闭的位置后台服务

java - 在 Android Room 数据库中存储 List<Object>

android - AndEngine 和 TimerHandlers : referencing a member variable in a scene

java - SwipeRefreshLayout 阻止 android.widget.switch 拖动

java - 如何使用从服务器收到的以下响应并将其保存到数据库

android - 从 RecyclerView 单击 CardView 加载 fragment

Android 在应用程序中运行 su

android - 如何创建 xml 的 id?