2017-04-15 67 views
1

我有3個ListView的在我的活動,我想同時滾動它們所有在一起,所以我用Scrollview >>線性佈局>> 3列表視圖。但還是他們每個人單獨在這裏滾動 是XML代碼:Listview doesnt scroll synchrologicly

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_order_items" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.nir.nestleapp.OrderItemsActivity"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="410dp"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="500dp" 
     android:orientation="horizontal"> 
     <ListView 
      android:layout_width="125dp" 
      android:id="@+id/ItemNameList" 
      android:layout_height="372dp"> 

     </ListView> 

     <ListView 
      android:id="@+id/ItemPriceList" 
      android:layout_width="125dp" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_toEndOf="@+id/QuantityList"> 
     </ListView> 
     <ListView 
      android:id="@+id/QuantityList" 
      android:layout_width="125dp" 
      android:layout_height="match_parent" 
      android:layout_alignParentTop="true" 
      android:layout_toEndOf="@id/ItemPriceList"> 

     </ListView> 

    </LinearLayout> 
    </ScrollView> 
    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="10dp" 
     android:id="@+id/button3" /> 

</RelativeLayout> 
+0

ListView處理它自己的滾動,所以你通常不應該把它放在一個ScrollView父類中。重構代碼以使用單個ListView(使用自定義適配器合併到不同的內容),或者只使用一個線性佈局的ScrollView。 – RobCo

回答

1

你不應該把一個ListView滾動型裏面,因爲ListView控件類實現了自己的滾動,它只是不接受手勢,因爲他們都由父ScrollView處理。

Your Question has Answer Here

1

不要使用ListView控件(S)爲滾動型。

將RecyclerViews用於NestedScrollView。

入住這Question

此外,我不知道你要實現什麼,但你可以使用不同類型的項目爲一體的ListView或RecyclerView。