2017-06-06 275 views
0

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

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

我的代码:

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

看到这一点:HTTPS :// STAC krollflow.com/questions/27646209/disable-scrolling-for-listview-and-enable-for-whole-layout – rafsanahmad007

+0

不要把Scrollable View放在另一个Scrollable View中(总之不要把ListView放在ScrollView里面) – Selvin

回答

0

尝试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> 
+0

它会滚动当我滚动布局。但我想在用户尝试在列表视图中滚动时滚动布局 – Vji

0

试试这个,取出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>