B. Money
B. Money

Reputation: 931

Why is alignParentRight not working?

I'm a noob to android development and I am having issues constructing a layout. I have a relative layout containing a textview and a linear layout containing two checkboxes. I want the textView to appear to the left and the linear layout to appear on the right of the linear layout flush with the edge. Currently, the textview and linearlayout appear on top of each other. Any help is greatly appreciated.

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:text="Rotated Shelf:           " 
                android:layout_gravity="center_vertical"/>

            <LinearLayout
                android:id="@+id/rotated"
                android:layout_width="match_parent"
                android:layout_height="32dp"                   
                android:layout_alignParentRight="true">                  

                <CheckBox
                    android:id="@+id/rotatedshelfYES"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Yes"
                    android:layout_toLeftOf="@+id/rotatedshelfNO"
                     />

                <CheckBox
                    android:id="@+id/rotatedshelfNO"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="75dp"
                    android:text="No"
                    android:layout_alignParentRight="true" />
            </LinearLayout>
        </RelativeLayout>

Upvotes: 0

Views: 4563

Answers (4)

user1931418
user1931418

Reputation:

Use you have to set android:layout_width in linear layout equal to wrap_content not match_parent since match_parent is used when we want to equal the width/height as the parent of the widget/container and wrap_content as name suggest requires space only to write the caption of view/container, no extra space required.

Upvotes: 0

scf
scf

Reputation: 406

If you want to align the right edge of your TextView with the left edge of your LinearLayout (i.e. TextView to the left of LinearLayout) you should use

android:layout_toLeftOf="@+id/rotated"

in your TextView properties.

Upvotes: 0

Diogo Bento
Diogo Bento

Reputation: 207

on the LinearLayout add android:layout_toRightOf="@+id/textView2"

Upvotes: 0

NagarjunaReddy
NagarjunaReddy

Reputation: 8645

try like this your textview write with in linear-layout and set android:layout_weight="" it working nice

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/rotated"
        android:layout_width="match_parent"
        android:layout_height="32dp"
        android:layout_alignParentRight="true" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight=".5"
            android:paddingLeft="5dp"
            android:text="Rotated Shelf:           " />

        <CheckBox
            android:id="@+id/rotatedshelfYES"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="Yes" />

        <CheckBox
            android:id="@+id/rotatedshelfNO"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="No" />
    </LinearLayout>
</RelativeLayout>

Upvotes: 1

Related Questions