2012-03-29 35 views

回答

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

[鏈接](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

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> 
相關問題