2016-05-29 15 views
0

Guten Tag,LinearLayout mit TextView auf der linken Seite und RadioButton auf der rechten Seite?

Ich versuche, eine Ausrichtung wie diese zu tun:

http://i.imgur.com/ArAEiZC.png

es zu tun habe ich versucht, den folgenden Code:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="0sp"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Dark background" 
     android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

    <RadioButton android:id="@+id/radio_darkbackground" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:onClick="onRadioButtonClicked" 
     android:layout_gravity="right" 
     android:gravity="right"/> 
</LinearLayout> 

Wie Sie sehen können, Ich lege die Layout Gravity und Gravity auf "Right", aber es funktioniert nicht und sieht so aus:

http://i.imgur.com/JDzwEJI.png

Antwort

2

Ihren Code dies ändern:

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Dark background" 
      android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

     <RadioButton android:id="@+id/radio_darkbackground" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:onClick="onRadioButtonClicked" 
        android:layout_gravity="right"/> 
    </FrameLayout> 
2

try this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="0sp"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Dark background" 
     android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

    <RadioButton 
     android:id="@+id/radio_darkbackground" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="right" 
     android:gravity="right" 
     android:onClick="onRadioButtonClicked" /> 
</RelativeLayout> 
+0

Es funktioniert in beide Richtungen. Was ist die beste Lösung? Vielen Dank ! –

+0

Relatives Layout ist das beste für dieses Design, da FrameLayout zu unterschiedlichen Zwecken verwendet wird. FrameLayout soll mit der Z-Achse arbeiten. Das heißt, Sie können Ihre Ansichtselemente übereinander stapeln. <: Layout_width = "0DP" android: layout_height = "0DP" android: layout_weight = "1" Ansicht android> 'einen leeren Raum in der füllen – Masum

1
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:orientation="horizontal"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Dark background" 
     android:textAppearance="@style/TextAppearance.AppCompat.Title"/> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="1"></View> 
    <RadioButton 
     android:id="@+id/radio_darkbackground" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="onRadioButtonClicked"/> 
</LinearLayout> 
+0

bitte eine Erklärung auf Ihre Antwort – Everettss

+0

Sie verwenden, um die' hinzufügen Mitte, damit wir den gewünschten Effekt erzielen können – caikai

Verwandte Themen