另一个列表视图内的ListView
我必须在垂直列表视图内制作一个水平列表视图。两个列表视图都可以有任意数量的元素,并且都需要可滚动。另一个列表视图内的ListView
我将如何实现这一目标,因为我读过android不支持列表视图层次结构。
谢谢!
为了实现这一目标这一点,你必须做到以下几点::
- 形成具有单一的LinearLayout一个垂直滚动型。
- 现在这里面的LinearLayout创建水平列表视图所示在下面的实施例:
因此这将让你在屏幕垂直滚动以及平铺在每个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);
Scrollviews不能嵌套......但却但是......你可以采取一个单亲的LinearLayout在里面,你可以保留多个ListView。因此ScrollView将有一个子元素Linearlayout。 – 2012-07-30 12:31:26
但在这种情况下,我不知道我需要做的任何listViews的数量,因为它们是随机的。我将如何实现这一目标? – gauravsapiens 2012-07-30 13:14:34
请检查我的编辑 – 2012-07-31 04:19:22
<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>
我建议使用一个ListView垂直滚动和使用的LinearLayout滚动型内做水平滚动。
的ListView - 第1项: - HorizontalScrollView - 的LinearLayout(方向:横向)
这是不可能的,但你可以做到这一点我已经使用和对我来说工作一招。 您可以停止(中断)通过使用此列表视图外小号滚动显示方式:)
假设你有水平列表视图HV内部的ListView LV,那么你必须写在下面的列表视图 -
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;
}
});
的触摸方法滚动视图不能嵌套。 [查看更多] [1]。 [1]:http://*.com/questions/4490821/scrollview-inside-scrollview – Snicolas 2012-07-30 12:28:54