【问题标题】:Scrollable Activity, non-scrollable ListView - Android可滚动的 Activity,不可滚动的 ListView - Android
【发布时间】:2019-05-19 10:25:40
【问题描述】:

我需要一种方法使 Activity 可滚动,但 ListViews 不可滚动。我尝试了我发现的不同方法,但到目前为止它们都没有奏效。

【问题讨论】:

  • 你能详细说明你为什么想要这个吗?
  • 如果你想要一个非滚动的View,那么使用ListView 真的没有意义。请改用垂直的LinearLayout

标签: java android listview android-activity scrollable


【解决方案1】:

您是否尝试过使用NestedScrollView?它适用于RecyclerView,但我不确定ListView

试试这样的。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <!-- Your header above your list. -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="My Header" />

        <!-- The list and it's contents. -->
        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- The footer below your list. -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="My Footer" />

    </LinearLayout>


</android.support.v4.widget.NestedScrollView>

【讨论】:

    【解决方案2】:

    如果你能提供更多细节可能会更好。 当我们有一个具有不同值的项目列表时,我们使用ListView。对于我们的视图可能会溢出屏幕并且可能不可见的场景,ScrollView 或者在某些情况下NestedScrollView 是解决问题的答案。记得把所有的内容都放在一个 Layout 标签里,比如LinearLayout,然后放到ScrollView里面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-18
      • 2011-03-11
      • 2013-09-19
      • 2020-05-31
      • 1970-01-01
      • 2012-11-20
      相关资源
      最近更新 更多