使用相對或線性佈局,如何在水平居中佈局頂部的文本字段和底部有4個按鈕全部顯示在同一行上,並在它們之間具有相同的空間。android佈局 - 頂部和底部
0
A
回答
2
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp" >
<requestFocus />
</EditText>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn 1 " />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn1"
android:text="btn 2 " />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn2"
android:text="btn 3 " />
<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn3"
android:text="btn 4 " />
</RelativeLayout>
</RelativeLayout>
+0
很好的答案,正是我問的。我怎麼能水平居中這些按鈕在底部? – user706315 2012-02-13 14:56:19
+0
看到我更新我的答案 – 2012-02-13 15:04:46
0
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Android!"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button1"
android:layout_weight="1" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button2"
android:layout_weight="1" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button3"
android:layout_weight="1" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button4"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
1
對於頂部的按鈕,你可以做,使用圖形佈局界面。只需添加您的文本框,並設置它的以下屬性:
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
對於底部的按鈕,你應該添加的LinearLayout具有以下屬性:
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
,並把你的4個按鈕與android:layout_weight="1"
內。
相關問題
- 1. 如何設置頂部和底部的佈局Android
- 2. 佈局問題:如何在頂部和底部放置東西?
- 3. ListView頂部和底部按鈕的佈局?
- 4. 頂部和底部的佈局奇怪的白色顏色
- 5. 在主佈局的頂部和底部放置包含的佈局
- 6. 距頂部佈局指南和底部佈局指南的距離相等
- 7. Android佈局和帶到頂部
- 8. 中心底部和頂部視圖
- 9. 在屏幕頂部和底部的LinearLayout
- 10. android - imagebutton - 放置頂部和底部?
- 11. android ImageView allways頂部和底部
- 12. Android頂部和底部菜單
- 13. Android - FrameLayout有兩行 - 頂部和底部?
- 14. ImageView在layout_height =「wrap_content」的android XML佈局中有填充頂部和底部
- 15. Android - 佈局問題 - 文字瀏覽頂部中心和底部中心
- 16. MPAndroidChart - 刪除頂部和底部空間
- 17. 五部分頂部佈局
- 18. 頂部div出現在底部和底部到頂部
- 19. TextView重疊在頂部和底部
- 20. 頂部和底部邊框
- 21. 顏色過渡到佈局從底部到頂部漸變
- 22. 在ListView的頂部和底部添加空間,以便頂部和底部項目可以居中
- 23. 引導3:頂部和底部
- 24. Android如何在兩個佈局頂部佈局佈局
- 25. 如何修復在底部使用包括不同佈局在Android的單個佈局中的底部底部
- 26. android無法顯示佈局的底部
- 27. Android佈局:底部有3個按鈕
- 28. 覆蓋佈局底部的廣告Android
- 29. 添加布局屏幕底部的Android
- 30. 傾斜底部的Android佈局
你的問題聽起來像有人把它作爲家庭作業,你應該自己嘗試,然後如果你仍然遇到困難,問你迄今爲止嘗試過的問題。 – triggs 2012-02-13 14:08:21