我想在一個屏幕上顯示三個不同的垂直部分,在我的Android佈局中,每個屏幕佔用屏幕的三分之一,頂部一個,中間一個,一個在底部。每個部分有一個TextView
和一個ListView
,並且ListViews
可以滾動以便您可以看到所有項目,但整個頁面不會移動。我曾嘗試將每個TextView
和ListView
放在LinearLayout
中,並將每個LinearLayout
的高度設置爲屏幕總高度的三分之一,但第一個ListView
只顯示其中的所有項目,佔用大部分屏幕,另一個部分被推下。我也嘗試使用layout_weights,但由於某種原因,它不起作用。 (編輯:設置layout_weight="1"
結束了工作,我不確定我第一次做錯了什麼)我該如何做這項工作,或者有更好的方法去做這件事?在Android佈局中顯示3個相同高度的可滾動ListViews
1
A
回答
1
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView android:layout_width="0dp" android:layout_weight="1"
android:layout_height="match_parent" android:background="#FF0000"/>
<ListView android:layout_width="0dp" android:layout_weight="1"
android:layout_height="match_parent" android:background="#00FF00">
<ListView android:layout_width="0dp" android:layout_weight="1"
android:layout_height="match_parent" android:background="#0000FF">
</LinearLayout>
這會給你三個等寬的列:使其行,更改方向垂直和交換的layout_height
和layout_width
值對每個列表視圖。如果您需要添加TextView
,則必須在此代碼中使用相同的寬度/高度/重量,並將ListView
和TextView
排列在內,以使其在此代碼中的排列視圖爲RelativeLayout
LinearLayout
或FrameLayout
。爲了最有效地做到這一點,請使用Framelayout
並在列表視圖上使用邊距來抵消TextView
。您可以通過使用TextView
中的layout_gravity
將TextView
相對於FrameLayout
中的ListView
。
IE(交換第一 「列」):
<FrameLayout android:orientation="vertical" android:layout_width="0dp"
android:layout_weight="1" android:layout_height="match_parent"
android:background="#FF0000">
<TextView android:text="Column!" android:background="#3Eff0000"
android:layout_height="40dp" android:layout_width="match_parent">
<ListView android:layout_marginTop="48dp" android:layout_height="match_parent"
android:layout_width="match_parent" android:background="#8Aff0000"/>
</FrameLayout>
0
使用此:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ff89ff91">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#1"
android:id="@+id/textView"
android:padding="5dp"
android:gravity="center" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_below="@+id/textView" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff8177">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#2"
android:id="@+id/textView2"
android:padding="5dp"
android:gravity="center" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView2"
android:layout_below="@+id/textView2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffe85d">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#3"
android:id="@+id/textView3"
android:padding="5dp"
android:gravity="center" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView3"
android:layout_below="@+id/textView3" />
</RelativeLayout>
</LinearLayout>
相關問題
- 1. 在Android中的單親佈局中顯示兩個表的ListViews?
- 2. Android佈局問題,滾動視圖中的幾個ListViews
- 3. Android:佈局與文字高度相同
- 4. Android相對佈局高度
- 5. 單個佈局滾動中的四個Listviews
- 6. 滾動相對佈局不顯示底部的佈局
- 7. android佈局 - 滾動視圖不顯示
- 8. 3列布局需要高度相等
- 9. 顯示可變數據量的相同高度的3列
- 10. 如何在android中動態設置相對佈局的高度
- 11. Android佈局 - 製作可滾動佈局
- 12. 在滾動視圖中具有相同寬度和高度的三個UIButton上的自動佈局
- 13. 單個滾動2個相同的佈局在不同的div?
- 14. 在同一屏幕上製作2個Android ListViews的高度相同
- 15. Android佈局在相關佈局下的Listview高度調整
- 16. Android可滾動佈局
- 17. 引導3:在不同高度顯示相同高度的圖像
- 18. Android的兩個ListViews間距和佈局
- 19. css列布局中間列顯示與右列相同的高度
- 20. android可滾動的活動佈局
- 21. 在android中滾動顯示的佈局中顯示廣告(頂部或底部)
- 22. Android佈局:儘可能多地顯示ImageView而不滾動
- 23. 可滾動的相對佈局與ImageViews
- 24. 不同高度的流動框佈局
- 25. 相對佈局 - android - 使相對佈局滾動
- 26. Android的佈局自動高度
- 27. 全屏幕的Android佈局與具有相同高度
- 28. 設計引導3頁面佈局動態保持高度,滾動,寬度
- 29. Android相對佈局不滾動
- 30. 如何在Android Wear和移動設備上同時顯示相同的佈局
謝謝你,這個工作;最初我曾嘗試使用權重,但由於某種原因,它不起作用,但此方法確實有效! – ravensgo 2015-03-31 21:26:20