我必須在垂直列表視圖內製作一個水平列表視圖。兩個列表視圖都可以有任意數量的元素,並且都需要可滾動。另一個列表視圖內的ListView
我將如何實現這一目標,因爲我讀過android不支持列表視圖層次結構。
謝謝!
我必須在垂直列表視圖內製作一個水平列表視圖。兩個列表視圖都可以有任意數量的元素,並且都需要可滾動。另一個列表視圖內的ListView
我將如何實現這一目標,因爲我讀過android不支持列表視圖層次結構。
謝謝!
爲了實現這一目標這一點,你必須做到以下幾點::
因此這將讓你在屏幕垂直滾動以及平鋪在每個ListView中。
例如。
<ScrollView>
<LinearLayout..... //this a vertically oriented layout
>
<ListView/>
.
.//This listViews Are Horizontal
.
<ListView>
</Linearlayout>
</ScrollView>
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://stackoverflow.com/questions/4490821/scrollview-inside-scrollview – Snicolas 2012-07-30 12:28:54