我試圖在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佈局 - 位置佈局
- 2. Android的佈局XML屬性和定位...
- 3. Android-佈局的正確定位
- 4. 在Android佈局錯誤的定位
- 5. Android的佈局和定位的問題
- 6. Android佈局元素職位
- 7. Android全屏佈局位置
- 8. 定位和屏幕大小的不同佈局 - Android
- 9. 相對佈局定位
- 10. 框架佈局內定位
- 11. CSS div佈局定位
- 12. 流體佈局定位div
- 13. Cytoscape.js - 定位多個佈局
- 14. 問題定位customLinear佈局
- 15. 學習DIV定位佈局
- 16. Android的佈局固定
- 17. Android自定義佈局
- 18. Android自定義ListViewItem佈局
- 19. Android - 自定義AutoCompleteTextView佈局
- 20. 自定義Android佈局
- 21. Android - 自定義佈局Inflater
- 22. Android DatePicker佈局定製
- 23. 的Android定製佈局AutoCompleteTextView
- 24. Android自定義listview相對佈局定位問題
- 25. Android layoutdisplay,佈局佈局。
- 26. Android:相對佈局佈局
- 27. Android禁用一個佈局的功能
- 28. Android佈局異常 - 實際佈局不符合Android Studio外觀。
- 29. Android查看位於網格佈局
- 30. 設備的Android佈局位置
發佈您迄今爲止已完成的代碼。 – deejay
我剛剛做了RelativeLayout,我把按鈕放在裏面,但它沒有很好地工作。 – mat
你爲什麼使用RelativeLayout? – deejay