1
A
回答
0
您可以使用嵌套LinearLayout
以及屬性layout_weight
和weightSum
來創建此佈局。要使此佈局scrollable
,使用ScrollView
作爲根佈局。
下面是一個工作示例:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical">
<!-- ROW1 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ff0000">
</LinearLayout>
<!-- ROW2 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- ROW2 COL1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#00ff00">
</LinearLayout>
<!-- ROW2 COL2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:orientation="vertical"
android:layout_weight="1"
android:weightSum="2">
<!-- ROW2 COL2 CHILD1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginBottom="4dp"
android:layout_weight="1"
android:background="#0000ff">
</LinearLayout>
<!-- ROW2 COL2 CHILD2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="#0000ff">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!-- ROW3 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- ROW3 COL1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#fff000">
</LinearLayout>
<!-- ROW3 COL2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:background="#fff000">
</LinearLayout>
</LinearLayout>
<!-- ROW4 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- ROW4 COL1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:background="#ff00ff">
</LinearLayout>
<!-- ROW4 COL2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:orientation="vertical"
android:layout_weight="1"
android:weightSum="2">
<!-- ROW4 COL2 CHILD1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginBottom="4dp"
android:layout_weight="1"
android:background="#00ffff">
</LinearLayout>
<!-- ROW4 COL2 CHILD2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="#00ffff">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
OUTPUT:
您還可以使用GridLayout
實現了這一觀點。
這是一個很好的tutorial約GridLayout
和一些stackOverflow answers。
希望這將有助於〜
相關問題
- 1. 給定一個網址創建一個網站的圖像
- 2. 以給定圖像的形狀創建UIButton
- 3. 爲圖像網格創建縮略圖
- 4. 在網頁上給定的圖像中創建一個點
- 5. 使用easel.js創建10x10圖像網格,其中圖像隨機交叉溶解
- 6. 根據圖像數量創建網格
- 7. 如何在QML中創建交錯網格視圖?
- 8. 如何創建圖像的數據綁定網格?
- 9. 創建形狀或圖像的筆劃
- 10. 這種「圖案」網格狀背景是如何創建的?
- 11. 如何動態創建圖像的網格視圖
- 12. 從表格創建圖像
- 13. 創建自定義.3vn文件? OpenGL三維形狀網格
- 14. C#創建給定大小的表格
- 15. Java - 從PNG圖像創建形狀(NullPointerException)
- 16. 創建自定義網格視圖以在android中顯示所選圖像
- 17. 交錯網格視圖老年人API
- 18. Android - OnScrollListener爲交錯網格視圖
- 19. 如何創建一個像iPhone主屏幕的圖標網格?
- 20. 創建帶圖像的CSS網格佈局
- 21. 如何創建我的圖像網格成5行
- 22. 如何從不同尺寸的圖像創建網格?
- 23. 在網格中的圖像上創建一個文本框
- 24. 如何創建模態圖像的網格?
- 25. 創建iOS中使用的UITableView圖像網格
- 26. CUDA:創建網格的邏輯圖片
- 27. 網格視圖的編程創建
- 28. 創建一個自定義的網格
- 29. 用漂亮的表格創建圖像
- 30. 如何創建給定飛機的鳥瞰圖像?
結帳以下鏈接:http://abhiandroid.com/materialdesign/recyclerview-as-staggered-grid-example.html –
@sapna,我已經檢查這個代碼視圖只被安排垂直但你可以檢查我有垂直同步視圖以及水平 –
希望這有助於:https://inducesmile.com/android/android-staggeredgridlayoutmanager-example-tutorial/ –