Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Align the Views

This is the part of the Code of a very long Layout.So posting of whole code was of no use.
I want to align the RED circle.Both the positions are shown in the RED colored circles.
The ParentLayout of whole activity is a RelativeLayout but has nothing to do with this.
Please help me.I have tried all the things that I knew.

enter image description here

<LinearLayout 
    android:id="@+id/thumbnail"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/texttitle"
    android:orientation="horizontal"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/Layoutborder"
    >
        <LinearLayout 
          android:id="@+id/Linearimagetop"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="3dip"
          android:layout_alignParentLeft="true"
          android:background="@drawable/image_bg"
          >
            <ImageView
                android:id="@+id/productimage1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/defaultimage"
                android:layout_below="@+id/texttitle"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Availability "
                android:textColor="@color/black"
                android:textStyle="normal" />  
            <View
                android:layout_width="1dp" 
                android:layout_height="fill_parent"
                android:background="@color/black"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"/>
            <TextView
                android:id="@+id/availibility"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="In Stock"
                android:textColor="#4A7023"
                android:textStyle="normal" 
                android:layout_marginLeft="3dp"/>
        </LinearLayout>
</LinearLayout>
like image 743
Haresh Chaudhary Avatar asked Sep 06 '12 08:09

Haresh Chaudhary


2 Answers

Change the 3rd LinearLayout to :

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="right"
    android:padding="5dp" >

Not sure if you are satisfied with that kind of layout.

like image 156
Aprian Avatar answered Oct 14 '22 02:10

Aprian


If this whole thing is inside a RelativeLayout, remove the outer LinearLayout (moving margins and such to the first child LinearLayout as required), and change the second child LinearLayout - the one with 5dp padding - to have

android:layout_alignParentRight="true"
android:layout_alignParentTop="true"

If you don't want to do this and have to keep the outer LinearLayout for some reason, move

android:layout_marginTop="20dp"

from the parent LinearLayout to the first child, and set layout_width of the second child to fill_parent, and add android:gravity="right" to it.

like image 28
Xono Avatar answered Oct 14 '22 02:10

Xono