【发布时间】:2015-03-09 08:11:33
【问题描述】:
我在同一个Activity 中使用 3 个ListViews,一个在另一个之下在一个接一个的页面中。
如果我使用android:layout_weight="1" 属性,它通过划分页面显示所有列表视图,但我不想划分活动屏幕,而是一个接一个地显示所有列表视图。
谁能指导我,belopw 是我的 xml 布局,其中包括这三个列表视图:-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/listTopTenBatsmans"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<ListView
android:id="@+id/listTopTenBowlers"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<TextView
android:id="@+id/tSometextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fall of Wickets"
android:textColor="@color/red"
android:textSize="18sp"
android:typeface="sans"
android:textStyle="bold"
android:background="#ffdfe5"
android:paddingLeft="5dp" />
<ListView
android:id="@+id/listTopTenFielders"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
在上面的 XML 中,第一个列表是根据我的适配器视图填充的,其中包含大约 10 个字段,而第二个列表也显示为根据适配器填充的大约 10 个列表字段,但它会自行滚动,并且作为textview 和 list view 没有出现,如果我使用 android:layout_weight="1" 属性,那么它通过划分活动屏幕显示所有 3 个 listvies 和 textview,但我需要一个接一个。
场景:-
ListView1
Element1 Ele1 E1
Element2 Ele2 E2
Element3 Ele2 E3
Element4 Ele4 E4
Element5 Ele5 E5
Element6 Ele6 E6
Element7 Ele7 E7
Element8 Ele8 E8
Element9 Ele9 E9
Element10 Ele10 E10
ListView2
Item1 It1 I1
Item2 It2 I2
Item3 It2 I3
Item4 It4 I4
Item5 It5 I5
Item6 It6 I6
Item7 It7 I7
Item8 It8 I8
Item9 It9 I9
Item10 It10 I10
SomeTextView
Listview3
Source1 Sou1 S1
Source2 Sou2 S2
Source3 Sou2 S3
Source4 Sou4 S4
Source5 Sou5 S5
Source6 Sou6 S6
Source7 Sou7 S7
Source8 Sou8 S8
Source9 Sou9 S9
Source10 Sou10 S10
【问题讨论】:
-
几个选项:在您的适配器中使用different view types,或查看
MergeAdapter,或RecyclerView。 -
@MH。感谢 MergeAdapter 为我工作,请将其写在答案中,以便我接受您的答案。再次感谢队友。
标签: android listview android-listview android-custom-view