2014-03-25 90 views
0

我有一個相對佈局,我想在水平方向上對齊一個圖像按鈕和2個普通按鈕 我想要做的是將佈局切換到橫向模式後,我想要兩個普通按鈕以相同的寬度水平延伸。水平伸展按鈕

肖像模式

----------------------------- 
ImageBtn [Button1] [Button2] 
----------------------------- 

風景模式

----------------------------------------------- 
ImageBtn [  Button1 ] [  Button2 ] 
----------------------------------------------- 

我不知道美容設計方法來做到這一點。

回答

0

你必須創建2個佈局文件這個工作,一個在正常的佈局目錄,一個在佈局土地目錄。

正常佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<Button 
    android:id="@+id/btn2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:background="#FFFF0000" 
    android:text="btn2" /> 

<Button 
    android:id="@+id/btn1" 
    android:background="#FF00FF00" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/btn2" 
    android:text="btn1" /> 

<ImageButton 
    android:background="#FF0000FF" 
    android:id="@+id/ibtn" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_toLeftOf="@id/btn1" 
    android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

景觀佈局(在佈局土地目錄):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="3" > 

<ImageButton 
    android:id="@+id/ibtn" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_toLeftOf="@id/btn1" 
    android:layout_weight="1" 
    android:background="#FF0000FF" 
    android:src="@drawable/ic_launcher" /> 

<Button 
    android:id="@+id/btn1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/btn2" 
    android:layout_weight="1" 
    android:background="#FF00FF00" 
    android:text="btn1" /> 

<Button 
    android:id="@+id/btn2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_weight="1" 
    android:background="#FFFF0000" 
    android:text="btn2" /> 

</LinearLayout> 
0

將所有3個按鈕放入LinearLayout,然後將Button1Button2分配爲layout_weight的相同值。

0

這是簡單的,我會給佈局你只用這個佈局.... 在這裏,我用了3按鈕,您只需更換一成圖像按鈕......這一切......所有最好

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/logo"> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:weightSum="3"> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_weight="1"/> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_weight="1"/> 
<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_weight="1"/> 

</LinearLayout> 

</RelativeLayout> 
0

您可以嘗試在佈局設計中使用重量。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

     <ImageButton android:layout_width="0dp" 
         android:layout_height="fill_parent" 
         android:layout_weight="1"/> 

     <TextView android:layout_width="0dp" 
         android:layout_height="fill_parent" 
         android:layout_weight="1"/> 

     <TextView android:layout_width="0dp" 
         android:layout_height="fill_parent" 
         android:layout_weight="1"/> 
</LinearLayout> 
+0

這將導致'ImageButton'舒展過。 –