2

I'm trying to make a layout first two textviews in a vertical arrangement, then text, then put a radiobutton on the most right side with linearlayout. However, even though I typed 'android:gravity="right"', it does not move and just stick there. If anyone has an idea, would you please help me? Below is my code.


<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
    <TwoLineListItem android:id="@+id/twoLineListItem1" android:layout_width="wrap_content" android:layout_height="wrap_content">
        <TextView android:id="@+id/textView1" 
                android:text="TextView"
                android:layout_width="wrap_content" android:layout_height="wrap_content" 
                android:textAppearance="?android:attr/textAppearanceMedium" />
        <TextView android:id="@+id/textView2" 
                android:text="TextView"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall" 
                android:paddingTop="30px"/>
    </TwoLineListItem>
    <TextView android:text="TextView" 
        android:id="@+id/textView3" 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:paddingTop="10px"/>

    <RadioButton android:id="@+id/radioButton1" 
            android:gravity="right"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
June
  • 265
  • 1
  • 8
  • 21

3 Answers3

3

Radio Button for right side align:

<RadioButton
                    android:id="@+id/radio0"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@null"
                    android:button="@null"
                    android:checked="true"
                    android:drawableRight="@drawable/presets_sel"
                    android:padding="12dp"
                    android:text="RadioButton 1" />
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/right_arrow_h" android:state_checked="true"/>
    <item android:drawable="@drawable/right_arrow_h" android:state_pressed="true"/>
    <item android:drawable="@drawable/right_arrow"></item>

</selector>
Ramesh Akula
  • 5,720
  • 4
  • 43
  • 67
2

You should make the width of radioButton to

android:layout_width="wrap_content"

And Add

android:layout_weight="1"

to both TwoLineListItem and TextView

droid kid
  • 7,569
  • 2
  • 32
  • 37
  • Thank you very much!:D If you don't mind, would you please let me know how the layout_weight made it work? – June Apr 22 '11 at 01:18
  • 1
    By giving weight to all three will divide the screen width equally.....still not clear then check the developer site. They provide good documentation. – droid kid Apr 22 '11 at 01:29
0

you are use android:layout_gravity="right"

bluekyg
  • 217
  • 1
  • 2