[英]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.