2011-03-10 2 views
1

지금은이 레이아웃 (수직 선형 레이아웃 안에 수평 상대 레이아웃)이 있지만 확인란 대신 라디오 버튼이 필요합니다 (사용자는 하나의 옵션 만 선택할 수 있어야합니다).radiogroup을 사용할 수 있도록 뷰를 배치하는 방법은 무엇입니까?

enter image description here

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="5dip" 
    android:layout_marginRight="5dip" 
    android:orientation="horizontal"> 

    <ImageView 
     android:src="@drawable/flag_en" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:layout_alignParentLeft="true" /> 

<TextView 
     android:text="English" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="10dip" 
     android:textStyle="bold" 
     android:textSize="20dip"    
     /> 

     <CheckBox android:id="@+id/checkbox4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:layout_alignParentRight="true" 
    /> 

    </RelativeLayout>  

    <RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="5dip" 
    android:layout_marginRight="5dip" 
    android:orientation="horizontal"> 

    <ImageView 
     android:src="@drawable/flag_dk" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:layout_alignParentLeft="true" /> 

<TextView 
     android:text="Dansk" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:textStyle="bold" 
     android:textSize="20dip"   
     /> 

     <CheckBox android:id="@+id/checkbox5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:layout_alignParentRight="true" 
    /> 

     </RelativeLayout> 
     <Button 
      android:id="@+id/ang_btn" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="ang" 
     /> 
     </LinearLayout> 

문제점을 radioGroup은 (상대 생략)의 선형 배열 내에 배치되어야하며, 그래서 상기 레이아웃 사용할 수 없다는 것이다.

어떻게하면 동일한 레이아웃 (여러 행, 3 열, 세 번째 열의 라디오 버튼)을 얻을 수 있으며 radiobutton과 함께 radiogroup을 사용할 수 있습니까?

편집

: 나는 로비 연못의 솔루션 (아래) 시도하고 난이 얻을 : enter image description here

내가 사용하는 수있는 내가 라디오 버튼 사이에 약간의 공간을 넣을 수 있으며,이 drawableLeft 있다면. drawableLeft와 android : doablePadding = "10dip"사이의 공간을 얻을 수있었습니다 (내 마지막 스크린 샷에는 표시되지 않음).

답변

3

라디오 그룹 및 라디오 버튼을 사용하고 이미지의 라디오 버튼에 android : drawableLeft를 사용합니다.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RadioGroup ...> 
     <RadioButton ... android:drawableLeft="@drawable/flag_en" android:text="English" /> 
    </RadioGroup> 
</LinearLayout> 
+0

@DixieFlatline @DixieFlatline 그래도 drawablePadding을 사용하거나 텍스트 시작 부분에 공백을 추가 할 수 있습니다. 당신이 라디오 버튼을 왼쪽 대신 오른쪽에 놓고 싶다고 지정할 수 없다는 것을 짜증나게한다. –

+0

고마워요. 선생님의 해결책이 저에게 효과적이었습니다. – Zia

관련 문제