我在缩放的相对布局上设置图像。但是,在设置图像时,布局对齐规则会被破坏。该图像应该与左侧对齐,但会发生移位。图像越大,图像放置的距离越远。其他布局项目(例如依赖图像位置的文本)也会移动。缩放后的图像看起来很好,除了它的位置。ImageView在设置图像时不符合布局规则
图像是200px,酒吧的高度的实际大小是70dp。我可以调整图像大小,但是我想知道为什么发生这种情况。
编辑 - 我自己也尝试设置图像动态image.setImageResource(R.drawable.placeholder);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/placeholder"
android:layout_alignParentLeft="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/icon"
android:layout_above="@id/username"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@id/username"
android:text="user name test"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/play_media_btn_toggle"
android:layout_marginTop="15dp"
android:id="@id/play"
android:layout_alignParentRight="true"
android:textOn=""
android:textOff=""/>
</RelativeLayout>
你能分享一下这个问题的截图吗? –
你在imageview上设置了“adjustViewBounds”吗?这可能是问题所在。 –
@ Sandervan'tVeer修复它谢谢!如果您回复,我会将其设置为正确的答案。我看到了这个文档,但并没有真正理解属性的作用。 – serenskye