6

我必须在垂直列表视图中创建一个水平列表视图。两个列表视图都可以有任意数量的元素,并且都需要可滚动。

我将如何实现这一点,因为我读过 android 不支持列表视图层次结构。

谢谢 !

自定义用户界面

4

4 回答 4

3

为此,您必须执行以下操作:

  1. 创建一个具有单个 LinearLayout 的 Vertical ScrollView。
  2. 现在在此 Linearlayout 中创建水平 ListViews,如下例所示:

因此,这将让您在Screen中垂直滚动以及在每个 ListView 中水平滚动。

例如。

<ScrollView>  

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

编辑: 动态添加 ListView 到 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);
于 2012-07-30T12:30:03.380 回答
1

我建议使用 ListView 垂直滚动并在 ScrollView 中使用 LinearLayout 来进行水平滚动。

ListView - 项目 1: - Horizo​​ntalScrollView - LinearLayout(orientation:horizo​​ntal)

也检查这个答案 - https://stackoverflow.com/questions/5398449/how-can-i-create-a-pulse-like-ui-for-an-android-application

于 2012-07-30T12:31:00.123 回答
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>
于 2012-07-30T12:30:38.460 回答
0

这是不可能的,但你可以做一个我也使用过并为我工作过的技巧。您可以使用此方法停止(中断)外部列表视图的滚动方法:)

假设您在 Horizo​​ntal Listview HV 中有 listview LV,那么您必须在列表视图的 touch 方法中编写以下内容 -

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;
            }
        });
于 2012-07-30T12:34:40.553 回答