我想在父佈局(相對佈局)中使用兩個孩子佈局(一個線性佈局和一個相對佈局),這樣兩個孩子佈局將佔用屏幕的一半,每個子佈局內的項目不會導致一個子佈局獲得比另一個佈局更大的寬度! 把兩個孩子佈局放在一個父母佈局裏面,在Android中有相同的權重分佈
0
A
回答
0
如果我從你的插圖中正確理解,紅框是一個RelativeLayout,而綠框是一個LinearLayout和一個RelativeLayout。
一個簡單的解決辦法是居中的RelativeLayout內的空查看並對準兩個子視圖反對:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/v_center" />
<View
android:id="@+id/v_center"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/v_center" />
</RelativeLayout>
這裏的一個不錯的小好處是,你可以通過指定在兩者之間提供一些空間視圖的尺寸。
但是,請注意,RelativeLayouts效率不高,嵌套它們是一個特別糟糕的主意。我建議使用層次結構查看器工具來檢查佈局時間,以確保其速度相對較快,並嘗試避免以這種方式嵌套佈局。
1
這是很容易,使用參數layout_weight在LinearLayout中的孩子,這樣的事情:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
</RelativeLayout>
</LinearLayout>
相關問題
- 1. Android佈局在另外兩個佈局的中間放置一個佈局
- 2. 相對佈局中的佈局權重
- 3. 在相對佈局中對佈局的權利分配 - android,
- 4. Android - 在另一個佈局上放置一個佈局
- 5. 如何在相對佈局內放置兩個佈局
- 6. 有兩個ListViews的佈局權重
- 7. Android如何把兩個佈局放在下面?
- 8. 指定的孩子已經有一個父級。在表佈局
- 9. 佈局裏面佈局
- 10. Android佈局 - 權重
- 11. 在父佈局中拉伸兩個佈局
- 12. Android的相對佈局對齊父權
- 13. 在佈局中使用每個孩子
- 14. 把佈局代碼放在哪裏
- 15. 如何把ListView和TextView放在android的相同佈局中?
- 16. 同樣在父佈局中設置多個視圖/佈局
- 17. Android:相對佈局佈局
- 18. D3樹佈局可視化 - 繼承多個父母的孩子
- 19. Magento在這個佈局中把js放在哪裏?
- 20. Android:在一個佈局中使用2個佈局
- 21. 如何把適當的權重佈局,佈局
- 22. 相對佈局權重
- 23. 的Android - 添加布局到父佈局
- 24. ImageViews裏面的相對佈局重疊
- 25. 佈局中有兩個佈局橫向Android
- 26. 在框架佈局中互相重疊的兩個佈局之間滑動
- 27. 設置佈局在另一個佈局
- 28. 同一行中的兩個按鈕>線性佈局內的相對佈局
- 29. Android listview裏面的相對佈局
- 30. 佈局重疊一個在另一個上方使用包括佈局在android