【问题标题】:Scroll view scrolls the list view not the layout滚动视图滚动列表视图而不是布局
【发布时间】:2017-06-06 14:24:48
【问题描述】:

我正在开发一个包含两个列表视图的布局。当列表视图扩展超出布局大小时,我想滚动布局,但它会滚动列表视图。

如何滚动布局而不是列表视图。

我的代码:

fragment_one.xml

        <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="10dip" >

                <ListView
                    android:id="@+id/list_nation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dip"
                    android:background="#B29090" >
                </ListView>

                <ListView
                    android:id="@+id/list_regional"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dip"
                    android:background="#4A9C67" >
                </ListView>
            </LinearLayout>

        </ScrollView>

【问题讨论】:

标签: android listview android-scrollview


【解决方案1】:

试试 NestedScrollView 之类的,

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="10dip" >

            <ListView
                android:id="@+id/list_nation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dip"
                android:background="#B29090" >
            </ListView>

            <ListView
                android:id="@+id/list_regional"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dip"
                android:background="#4A9C67" >
            </ListView>
        </LinearLayout>

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

【讨论】:

  • 当我在布局中滚动时它会滚动。但是当用户尝试在列表视图中滚动时我想滚动布局
【解决方案2】:

试试这个,去掉LinearLayout使用RelativeLayout

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

  <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ListView
        android:id="@+id/list_nation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:background="#B29090" >
         </ListView>

         <ListView
        android:id="@+id/list_regional"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:background="#4A9C67"  >
        </ListView>
  </RelativeLayout>
</ScrollView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 2019-06-09
    • 1970-01-01
    相关资源
    最近更新 更多