Android ImageView不会match_parent宽度
我有一个 1x20px 的 ImageView。该图像是 .9.png。我正在尝试使用 match_parent,但是当我在设备上运行该应用程序时,它不会拉伸以填充屏幕的宽度。以下是 ImageView 的 XML 代码
<ImageView
android:id="@+id/dividerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_bar"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside" />
对于如何让 ImageView 覆盖屏幕的整个宽度有什么想法吗?
I have an ImageView that is 1x20px. The image is a .9.png. I am trying to use match_parent but when I run the app on my device, it is not stretched to fill the width of the screen. Here's the code in the XML for the ImageView
<ImageView
android:id="@+id/dividerBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_bar"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside" />
Any ideas on how I can get the ImageView to cover the entire width of the screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它是 9 补丁,则需要将其设置为 imageview 的背景属性,以使其正确缩放。现在它正在尝试使用您提供的scaleType 标记来缩放图像,就像缩放任何其他图像一样。
尝试设置
并删除 src 属性
此外,如果您仅使用 imageView 来显示 9-patch,则可以切换到使用常规 View 而不是 ImageView。只要设置背景属性就可以了。
If it's a 9 patch it needs to be set as the background attribute of the imageview for it to scale properly. Right now it's trying to scale the image as it would any other image using the scaleType tag that you provided.
Try setting
and remove the src attribute
Additionally, if you are using the imageView only to display the 9-patch you can switch to using a regular View instead of the ImageView. As long as you set the background attribute you will be good to go.