android 9-patch 图形在图像视图中无法缩放
我的
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/ImageView01"
android:src="@drawable/phone80"></ImageView>
<ImageView android:id="@+id/ImageView02"
android:layout_height="wrap_content" android:src="@drawable/underline"
android:layout_width="fill_parent" android:layout_gravity="fill_vertical|fill_horizontal"></ImageView>
</LinearLayout>
第一张图像是固定大小的图像,根本不应该缩放。其右侧的图像应水平缩放至最大空间。源指向有效的 .9.png 文件。不幸的是,它总是只以其原始大小显示。我必须设置什么属性? ImageView 到底是正确的对象吗?
谢谢, 一个。
I have
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/ImageView01"
android:src="@drawable/phone80"></ImageView>
<ImageView android:id="@+id/ImageView02"
android:layout_height="wrap_content" android:src="@drawable/underline"
android:layout_width="fill_parent" android:layout_gravity="fill_vertical|fill_horizontal"></ImageView>
</LinearLayout>
The first image is a fixed size image which shouldn't scale at all. The image right of it should scale horizontally to the maximum space. The source points to a valid .9.png file. Unfortunatly it always only shows up in its original size. What property to I have to set? Is ImageView the right object at all?
Thanks,
A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需将
android:scaleType="fitXY"
添加到您的ImageView
中即可。例如对于 myimage.9.png:Just add
android:scaleType="fitXY"
to yourImageView
. For example for myimage.9.png:使用
android:background
代替。如果只是下划线,则可以使用View
而不是ImageView
。至于填充屏幕的其余部分,您可能需要使用TableLayout
来代替。另外,请确保您的 9 补丁正确。 1px 边必须是黑色的。 #000
Use
android:background
instead. And if it is just an underline, you can use aView
and not anImageView
. As for filling the remainder of the screen, you may want to use aTableLayout
instead.Also, make sure your 9-patch is correct. The 1px sides must be black. #000
另请检查以确保侧面的比例线不会一直延伸到图像的角落。我知道那里有黑色像素并没有什么意义,但我认为 Android 会忽略它们,但它实际上阻止了缩放工作。它还会在输出窗口中显示“错误:9-patch image xxx.9.png malformed”消息,但您可能没有注意到这一点。一旦我取出角落里的像素,它就开始为我工作。
Also check to make sure your scale lines on the sides don't extend all the way to the corners of the image. I knew it didn't really make sense for there to be black pixels there, but I figured Android would ignore them, but it actually prevents the scaling from working. It also gives you the "ERROR: 9-patch image xxx.9.png malformed" message in the output window, but you might not have noticed this. As soon as I took out the pixels in the corners, it started working for me.
尝试使用 setImageResource(9patchResourceID) 而不是 setImageBitmap 或 setImageBackground 它可以工作:)
Try using setImageResource(9patchResourceID) instead of setImageBitmap or setImageBackground and it works :)