Search code examples
androidimageviewalignment

Android ImageView layout alignment


How can change my layout to make image 1 more like image 2? I don't mind if it's the text that moves up or the image that moves up.

What I have

What I need

my layout file is like so :-

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.6"
            android:orientation="vertical" >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/imp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.4"
            android:orientation="vertical" >

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/stats_chr" />
                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right|center_vertical"
                    android:singleLine="true"
                    android:text="AA" />
            </LinearLayout>

Solution

  • Try this..

    Use android:gravity="top" for LinearLayout or android:layout_gravity="top" for ImageView

           <LinearLayout
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:layout_weight="0.6"
                android:orientation="vertical" >
    
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="top"
                    android:src="@drawable/imp" />
    
            </LinearLayout>