想用兩個LinearLayouts爲我的應用程序分割一個屏幕。我應該使用哪些參數來精確分割兩個相等的部分 - 第一個是LinearLayout,第二個是正下方。如何用兩個相等的LinearLayout分割屏幕?
回答
使用重量參數,大致的佈局將類似於這樣:
<LinearLayout android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="0dp"/>
<LinearLayout
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="0dp"/>
</LinearLayout>
您拼寫了第3個LinearLayout錯誤。 – Doomsknight 2012-09-05 13:16:08
@Doomsknight thx,修正! – 2012-09-09 07:53:58
查看本教程中有關使用layout_weight屬性的信息http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/ – 2012-09-24 18:19:43
只是把它在那裏:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:weightSum="4"
android:padding="5dp"> <!-- to show what the parent is -->
<LinearLayout
android:background="#0000FF"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="2" />
<LinearLayout
android:background="#00FF00"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1" />
</LinearLayout>
我後4-5年,但這樣做的最佳實踐回答這個問題這是下面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/secondView"
android:orientation="vertical"></LinearLayout>
<View
android:id="@+id/secondView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />
<LinearLayout
android:id="@+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/secondView"
android:orientation="vertical"></LinearLayout>
</RelativeLayout>
這是正確的做法是使用layout_的對於UI操作來說,重量總是很重的。 使用LinearLayout同等地分割佈局不是好的做法
- 1. 使用LinearLayout分割屏幕的問題
- 2. 如何分割三個div的屏幕
- 3. 如何用兩個按鈕分割屏幕?
- 4. 將主頁屏幕分割爲兩個屏幕
- 5. 將Android屏幕分成兩半等分
- 6. Cocos2d上的分割屏幕
- 7. libgdx如何將屏幕分割4份
- 8. 如何在iphone中分割屏幕?
- 9. 如何在屏幕上水平分割屏幕
- 10. 如何在兩個相等的部分
- 11. 分割屏幕一半CSS
- 12. SDL圖像分割屏幕
- 13. Javascript分割屏幕視圖
- 14. 如何在多於一個部分分割屏幕
- 15. 如何將C++控制檯屏幕分割成多個部分?
- 16. 分割屏幕在兩個(水平或垂直)
- 17. 將屏幕分割爲兩個視圖控制器SpritKit + Swift
- 18. 五等分劃分屏幕
- 19. 大於屏幕的LinearLayout
- 20. 保持在的LinearLayout屏幕
- 21. 用GTK +/gtkmm Grid分割屏幕
- 22. 分成兩個部分屏幕
- 23. 將屏幕分成與溢出相等的部分
- 24. 如何將一個NSArray分成兩個相等的部分?
- 25. 分割整數分成相等的塊
- 26. 如何將gridview拆分成相等的部分來填充屏幕
- 27. 如何使用LinearLayout將兩個圖像放在相反兩端?
- 28. LinearLayout被推下屏幕
- 29. fill_parent不填滿整個屏幕在LinearLayout
- 30. Xcode的分割屏幕分爲4個巨人按鈕
對每個佈局使用權重= 0.5 – Sephy 2010-08-06 15:10:33
兩個佈局的權重應該是「相同的」,不一定是分數 – Siddharth 2013-07-05 03:24:58