在Android中展示瞭如何在左側和右側用相同的線條創建TextView。 哪種佈局更適合用於此佈局表或相對?如何在同一行中創建左側的Textview和右側的兩個按鈕?
3
A
回答
1
您可以使用的LinearLayout實現這一
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_weight="1"
android:text="a text"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1">
</Button>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2">
</Button>
</LinearLayout>
0
最簡單的是使用如前面的回答指出了LinearLayout
(水平方向)。您還可以將佈局權重下的屬性設置爲1,以獲得每個按鈕和文本視圖。然後將所有這些對象的佈局寬度設置爲0.這將使您能按比例縮放每個對象水平佔用的區域的多少。例如,如果將Textview上的佈局權重設置爲2,將每個按鈕設置爲1,則textview將佔用水平空間的50%(2 /(2 + 1 + 1))。這樣可以更輕鬆地在不同設備上縮放對象,並希望能夠解決在這種情況下哪種佈局最適合的問題。
+0
http://stackoverflow.com/questions/9923811/how-to-create-textview-in-left-side-and-two-button-in-right-side-in-same-line非常有幫助 – 2012-04-02 08:09:19
1
對這種視圖最好使用相對佈局。使用android:layout_alignParentRight="true"
將右對齊並將android:layout_alignParentLeft="true"
與對齊左對齊。例如
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp" >
<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:textColor="#76D4F7"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
相關問題
- 1. 右側html中的兩行按鈕不會中斷左側
- 2. 的TextView在左側與右側非絕對值按鈕
- 3. 對齊按鈕左側,中間,右側
- 4. 如何使用兩個按鈕從中間頁面的左側和右側創建頁面的轉換?
- 5. 如何將textview放置在佈局的左側和右側?
- 6. 如何向Flexbox 3兒童,一個左側和兩個右側
- 7. 創建左側和右側的類名不同的對象
- 8. LinearLayout的左側是TextView,右側是RadioButton?
- 9. Mysql的加入不同行的兩個表的左側,同一行上右側
- 10. UIToolBar左側/右側按鈕文本
- 11. 放置Highchart右側和左側的下一個和上一個按鈕
- 12. 在火花按鈕的左側和右側添加兩個圖標
- 13. 如何在容器內部創建左側和右側?
- 14. 如何在左側和右側視圖上創建陰影?
- 15. divs在左側和右側
- 16. 在同一行和背景中排列左側按鈕和右側圖像按鈕
- 17. 如何創建帶有兩個箱子左側和盒體右側佈局
- 18. 如何使標題左側與右側和側按鈕在jquery移動
- 19. 左側和右側的行程sdg
- 20. 如何在另一個兩個(左側和右側)div之間居中div?
- 21. 如何在左側和右側的工具欄中添加按鈕
- 22. 屏幕左側和右側的jquery按鈕?
- 23. 如何對齊右側和左側
- 24. 加入左側和右側
- 25. CSS左側和右側
- 26. UIButton在左側和右側的圖像
- 27. 如何定位一個可滾動的DIV的左,右兩側的按鈕
- 28. 從另一個ViewController隱藏欄按鈕(左右兩側)?
- 29. 兩側(左側和右側)的bootstrap offcanvas示例
- 30. 如何僅在一條線上創建陰影左側和右側?
[鏈接](http://stackoverflow.com/questions/9923811/how-to-create-textview-in-left-side-and-two-button-in-right-side-in - 同行)謝謝 – 2012-04-02 08:08:07