AndroidAndroidAndroid
AndroidAndroidAndroid

Reputation: 383

ImageView Does not Align Left using android:layout_alignParentLeft="true" in RelativeLayout

I'm not sure exactly why this is happening - however I have an imageView I'm attempting to implement on the left side of my screen - however it is centered when I attempt to run the layout and I am unsure why.

Any suggestions are greatly appreciated.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ListView_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="1" >

    <RelativeLayout
        android:id="@+id/rl_ListView2"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:gravity="left" />

        <ProgressBar
            android:id="@+id/progressbar_Horizontal"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="340dp"
            android:layout_height="15dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:max="100"
            android:progressDrawable="@drawable/progressbar2" />

        <ImageView
            android:id="@+id/downloadbtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/progressbar_Horizontal"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp"
            android:src="@drawable/button_download" />

        <RelativeLayout
            android:id="@+id/footer"
            style="@android:style/ButtonBar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/saveButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RelativeLayout>
    </RelativeLayout>

</LinearLayout>

Upvotes: 1

Views: 1039

Answers (4)

Puneet Akhouri
Puneet Akhouri

Reputation: 41

I was facing a similar problems when I was not setting any fixed dimensions on the ImageView. Try giving the ImageView fixed height and width. Did the trick for me.

Upvotes: 0

genko stain champion
genko stain champion

Reputation: 101

Try this?

<ImageView
        android:id="@+id/downloadbtn"
        android:layout_width="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_height="wrap_content"
        android:layout_above="@+id/progressbar_Horizontal"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:src="@drawable/button_download"/>

This works for me :)

Upvotes: 0

bkurzius
bkurzius

Reputation: 4068

Your image width and height are set to "fill_parent" - try setting them both to "wrap_content".

Upvotes: 0

Awanish Raj
Awanish Raj

Reputation: 2009

Change the layout of your imageView1 as follows:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:adjustViewBounds="true"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="left" />

You had set the width of the imageView to fill the parent, which was causing the problem. This snippet fills height, then adjusts width according to the image's dimensions.

Upvotes: 1

Related Questions