Android:仅在尝试滚动文本视图时滚动工具栏

时间:2015-03-15 21:38:20

标签: android

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

<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>

我用来添加自定义工具栏。请告诉我如何在此文件中包含工具栏,以便在滚动文本时不会滚动

1 个答案:

答案 0 :(得分:2)

您应该将LinearLayout作为主要父级,并将工具栏(include)作为第一个子级,将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" >
        ...