2014-03-25 2 views
0

하나의 이미지 버튼과 2 개의 일반 버튼을 수평으로 정렬하고자하는 상대 레이아웃이 있습니다. 레이아웃을 가로 모드로 전환하면 두 가지 일반 버튼을 원합니다. 동일한 폭으로 수평으로 뻗어있다.늘이기 버튼

세로 모드 나는 이러한 목표를 달성하기 위해 뷰티 디자인 접근 방법을 모르는

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

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

가로 모드.

답변

0

정상적으로 작동하려면 2 개의 레이아웃 파일을 만들어야합니다. 하나는 일반 레이아웃 디렉토리에, 1 개는 레이아웃 - 랜드 디렉토리에 있습니다.

일반적인 레이아웃 (레이아웃 토지 디렉토리)

<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

LinearLayout에 3 개의 버튼을 모두 넣은 다음 Button1Button2layout_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'이 너무 스트레칭이 발생할 것입니다. –