2012-07-30 35 views
5

Tôi đã tạo chế độ xem danh sách theo chiều ngang bên trong chế độ xem danh sách dọc. Cả hai chế độ xem danh sách đều có thể có bất kỳ số phần tử nào và cả hai đều cần phải cuộn được.ListView bên trong một ListView khác

Làm cách nào để đạt được điều này vì tôi đã đọc android không hỗ trợ phân cấp chế độ xem danh sách.

Cảm ơn!

CUSTOM UI

+0

Scrollviews không thể lồng nhau. [Xem thêm tại đây] [1]. [1]: http://stackoverflow.com/questions/4490821/scrollview-inside-scrollview – Snicolas

Trả lời

3

Để đạt được điều này này, bạn phải làm như sau ::

  1. Tạo một scrollview Vertical có đơn LinearLayout.
  2. Bây giờ Tạo ListViews ngang bên trong LinearLayout này như trong Ví dụ dưới đây:

Do đó điều này sẽ cho phép bạn cuộn theo chiều dọc trong Screen cũng như ngang trong mỗi ListView.

ví dụ:

<ScrollView> 

    <LinearLayout..... //this a vertically oriented layout 
    > 
    <ListView/> 
    . 
    .//This listViews Are Horizontal 
    . 
    <ListView> 
    </Linearlayout> 
</ScrollView>  

Edit: Thêm động ListView với LinearLayout.

LinearLayout ll=(LinearLayout)findViewById(R.id.id_given_in_the_XML_file); 
ListView lv=new ListView(Activityname.this); 
. 
. 
. 
Do All ListView Processing Here 
. 
. 
. 
lv.setAdapater(adapter); 

ll.addView(lv); 
+0

Scrollviews không thể được lồng vào nhau ... nhưng nhưng nhưng ... bạn có thể tham gia một mẹ LinearLayout Độc thân và bên trong nó, bạn có thể giữ nhiều ListViews.Hence ScrollView sẽ có một Linearlayout con duy nhất. –

+0

Nhưng trong trường hợp này, tôi không biết số lượng listViews mà tôi cần thực hiện vì chúng là ngẫu nhiên. Làm thế nào tôi sẽ đạt được điều đó? – gauravsapiens

+0

Vui lòng kiểm tra Chỉnh sửa của tôi –

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ll" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Accounts" /> 
<ListView 
    android:id="@+id/Accounts" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:scrollbars="vertical" /> 
<View 
    android:layout_width="fill_parent" 
    android:layout_height="2dp" 
    android:background="#FF4500" /> 
<TextView 
    android:id="@+id/textView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Contacts" /> 
<ListView 
    android:id="@+id/con_listView" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:scrollbars="vertical" /> 
</LinearLayout> 
0

Nó không phải là có thể nhưng bạn có thể làm một thủ thuật mà tôi đã sử dụng và làm việc cho tôi quá. Bạn có thể ngừng (ngắt) ngoài listview s phương pháp cuộn bằng cách sử dụng này :)

Giả sử bạn có listview LV bên ngang listview HV sau đó bạn phải viết sau đây trong các phương pháp liên lạc của danh sách View-

lv.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View arg0, MotionEvent arg1) { 

       if(arg1.getAction() == MotionEvent.ACTION_DOWN || arg1.getAction() == MotionEvent.ACTION_MOVE) 
       { 
       HV.requestDisallowInterceptTouchEvent(true); 

       } 
       return false; 
      } 
     }); 
Các vấn đề liên quan