我試圖在android中做GridLayout,但我並沒有屈服於按鈕是平等的,我想做的佈局分爲3部分,部分將顯示3個按鈕,並按鈕將顯示所有的屏幕。 有人可以幫助我的代碼?Android佈局不成功定位
-2
A
回答
0
在你的xml中試試這個。
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
這將創建一個與每個col等寬的gridview。您可以通過將numColumns
指定爲所需的數字來設置列數。
要使用LinearLayout,您可以將子視圖的Layout_weight設置爲等值。
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight = "1"/>
<TextView
android:id="@+id/tv2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight = "1"/>
<TextView
android:id="@+id/tv3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight = "1"/>
</LinearLayout>
你並不需要設置weightSum
父佈局只是簡單的設置孩子layout_weight
,不要忘記設置寬度或高度子視圖0dp。
設置爲layout_width
到0dp
爲水平和layout_height
到0dp
垂直。並根據需要將另一個設置爲match_parent
或wrap_content
相關問題
- 1. Android FragmentTabHost佈局定位
- 2. XML Android定位佈局
- 3. Android佈局 - 位置佈局
- 4. Android佈局定位不正確
- 5. Android奇怪的佈局定位
- 6. Android的佈局XML屬性和定位...
- 7. iOS:相對定位像Android的佈局
- 8. Android - 佈局:定位按鈕問題
- 9. Android - 錯誤的佈局定位
- 10. Android佈局/視圖旋轉/定位
- 11. Android在佈局中的定位
- 12. Android佈局定位。兩行文字
- 13. 絕對定位在佈局Android
- 14. Android的相對佈局定位
- 15. Android的佈局和定位的問題
- 16. 在Android佈局錯誤的定位
- 17. Android-佈局的正確定位
- 18. Android相對佈局定位規模?
- 19. 佈局和定位
- 20. Android全屏佈局位置
- 21. Android佈局元素職位
- 22. Android動態生成佈局
- 23. 動態佈局生成Android
- 24. 定位在不同佈局的按鈕
- 25. 定位和屏幕大小的不同佈局 - Android
- 26. HTML按鈕佈局定位
- 27. 定位元素表佈局
- 28. Cytoscape.js - 定位多個佈局
- 29. 佈局相對定位
- 30. 學習DIV定位佈局
發佈您迄今爲止已完成的代碼。 – deejay
我剛剛做了RelativeLayout,我把按鈕放在裏面,但它沒有很好地工作。 – mat
你爲什麼使用RelativeLayout? – deejay