mercredi 27 mai 2015

layout_alignParentRight not working for relative layout inside linear layout

I have two relative layout inside linear layout. I want the first relative layout left align and the second relative layout right align. I set the following line in the second relative layout but it is not working.

android:layout_alignParentRight="true"

and my full xml file goes here.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    xmlns:android="http://ift.tt/nIICcg">

    <LinearLayout xmlns:android="http://ift.tt/nIICcg"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="100">

    <RelativeLayout
        android:id="@+id/left"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="45"
        android:background="@drawable/listview">
        <ImageView
            android:id="@+id/leftPanelImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:src="@drawable/sports"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="left panel"
            android:layout_marginTop="5dp"
            android:layout_below="@id/leftPanelImage"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="45"
        android:background="@drawable/listview"
        android:layout_alignParentRight="true"
        >
        <ImageView
            android:id="@+id/rightPanelImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:src="@drawable/sports"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="right panel"
            android:layout_marginTop="5dp"
            android:layout_below="@id/rightPanelImage"/>
    </RelativeLayout>



</LinearLayout>
</ScrollView>

My current code gives an output like this. Second layout start after first layout. I want it to start from the right from parent.

enter image description here

So my question is how can I set the second relative layout right align.

Thank you.

Aucun commentaire:

Enregistrer un commentaire