2011-05-27 52 views
0

在我的代碼我想有以下幾點:Android的整個屏幕,用一系列的TextView和按鈕

<LinearLayout> 
<LinearLayout> 
<Button> 
</LinearLayout> 
<TextView> 
<TextView> 
<TextView> 
<TextView> 
<LinearLayout> 
<Button> 
</LinearLayout> 
</LinearLayout> 

Whare包裝是水平的(從左至右)

我TextView的的在代碼中進行更改,我希望左右按鈕位置固定在屏幕的最左側和最右側。我怎樣才能做到這一點?

回答

0

設置按鈕屬性安卓重力=「左」或Android:重力=「右」

0

使用layout_weight使textviews擴展爲佔用所有可用空間,這將推動按鈕的邊緣,像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 
    <Button 
     android:id="@+id/btnLeft" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Left" 
    /> 
    <TextView 
     android:id="@+id/widget36" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TV1" 
     android:layout_weight="1" 
    /> 
    <TextView 
     android:id="@+id/TV2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TV2" 
     android:layout_weight="1" 
    /> 
    <TextView 
     android:id="@+id/TV3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TV3" 
     android:layout_weight="1" 
    /> 
    <TextView 
     android:id="@+id/TV4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TV4" 
     android:layout_weight="1" 
    /> 
    <Button 
     android:id="@+id/btnRight" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Right" 
    /> 
    </LinearLayout> 
</LinearLayout>