android 9-patch 图形在图像视图中无法缩放

发布于 2024-10-20 18:02:40 字数 793 浏览 7 评论 0原文

我的

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

今天小雨转甜 2024-10-27 18:02:40

只需将 android:scaleType="fitXY" 添加到您的 ImageView 中即可。例如对于 myimage.9.png:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/myimage"
    android:scaleType="fitXY" />

Just add android:scaleType="fitXY" to your ImageView. For example for myimage.9.png:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/myimage"
    android:scaleType="fitXY" />
﹏半生如梦愿梦如真 2024-10-27 18:02:40

使用 android:background 代替。如果只是下划线,则可以使用 View 而不是 ImageView。至于填充屏幕的其余部分,您可能需要使用 TableLayout 来代替。

另外,请确保您的 9 补丁正确。 1px 边必须是黑色的。 #000

Use android:background instead. And if it is just an underline, you can use a View and not an ImageView. As for filling the remainder of the screen, you may want to use a TableLayout instead.

Also, make sure your 9-patch is correct. The 1px sides must be black. #000

不再见 2024-10-27 18:02:40

另请检查以确保侧面的比例线不会一直延伸到图像的角落。我知道那里有黑色像素并没有什么意义,但我认为 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.

南冥有猫 2024-10-27 18:02:40

尝试使用 setImageResource(9patchResourceID) 而不是 setImageBitmap 或 setImageBackground 它可以工作:)

Try using setImageResource(9patchResourceID) instead of setImageBitmap or setImageBackground and it works :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文