繁体   English   中英

ImageView不使用RelativeLayout中的android:layout_alignParentLeft =“ true”左对齐

[英]ImageView Does not Align Left using android:layout_alignParentLeft=“true” in RelativeLayout

我不确定为什么会这样-但是我有一个imageView试图在屏幕的左侧实现-但是当我尝试运行布局时它居中,我不确定为什么。

任何建议,不胜感激。

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

如下更改imageView1的布局:

<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" />

您已设置imageView的宽度以填充父级,这导致了问题。 该代码段将填充高度,然后根据图像的尺寸调整宽度。

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

尝试这个?

<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"/>

这对我有用:)

当我没有在ImageView上设置任何固定尺寸时,我遇到了类似的问题。 尝试给ImageView固定的高度和宽度。 为我做了把戏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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