简体   繁体   English

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

[英]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. 我不确定为什么会这样-但是我有一个imageView试图在屏幕的左侧实现-但是当我尝试运行布局时它居中,我不确定为什么。

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: 如下更改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" />

You had set the width of the imageView to fill the parent, which was causing the problem. 您已设置imageView的宽度以填充父级,这导致了问题。 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 . 当我没有在ImageView上设置任何固定尺寸时,我遇到了类似的问题。 Try giving the ImageView fixed height and width. 尝试给ImageView固定的高度和宽度。 Did the trick for me. 为我做了把戏。

暂无
暂无

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

相关问题 如何在代码中将android:layout_alignParentLeft属性设置为imageview? - How to set android:layout_alignParentLeft attribute to imageview in code? 在Android 4.1.2中,layout_centerInParent会覆盖layout_alignParentRight / layout_alignParentLeft - layout_centerInParent overrides layout_alignParentRight/layout_alignParentLeft in Android 4.1.2 layout_alignParentRight或layout_alignParentLeft是否适用于包含布局? - Are layout_alignParentRight or layout_alignParentLeft work for include layout? Android RelativeLayout alignParentRight无法正确对齐Imageview - Android RelativeLayout alignParentRight does not properly align Imageview 类型错误:在包中找不到属性“ layout_alignparentleft”的资源标识符 - Type error: No resource identifier found for attribute 'layout_alignparentleft' in package RelativeLayout- android:layout_centerHorizo​​ntal =“true”和android:layout_centerVertical =“true”不要将imageview居中 - RelativeLayout- android:layout_centerHorizontal=“true” and android:layout_centerVertical=“true” dont center the imageview Android RelativeLayout ALIGN_LEFT无法正常工作 - Android RelativeLayout ALIGN_LEFT not working 在RelativeLayout中将layout_weight用于ImageView - Using layout_weight for ImageView in RelativeLayout 将ImageView对齐到RelativeLayout中TextView的中心 - Align ImageView to center of a TextView in RelativeLayout 无法将ImageView与RelativeLayout的底部对齐 - Unable to align ImageView to bottom of RelativeLayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM