简体   繁体   中英

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>

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.

您的图片宽度和高度设置为“ fill_parent”-尝试将它们都设置为“ wrap_content”。

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM