Android 9 补丁图像按钮未按预期缩放

发布于 2024-12-12 17:51:19 字数 917 浏览 3 评论 0原文

我正在尝试使用 9-patch 技术来创建按钮。

它在 Eclipse 的布局窗口中看起来几乎很棒

Eclipse布局

当我运行它时在模拟器中它显示如下:

Emulator view

这是实际的 PNG 图像

实际 PNG

选择器 XML

<item android:drawable="@drawable/splash_facebook_button" />

布局中的按钮代码

   <Button
        android:id="@+id/button1"
        android:layout_width="208dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dip"
        android:background="@drawable/splash_facebook_button_selector"
        android:text="Sign up with Facebook" />

I am trying to use the 9-patch technique to create the button.

It looks almost great in the Layout Window of Eclipse

Eclipse layout

When I run it in the emulator it shows up like this:

Emulator view

Here is the actual PNG image

Actual PNG

Selector XML

<item android:drawable="@drawable/splash_facebook_button" />

Button Code in Layout

   <Button
        android:id="@+id/button1"
        android:layout_width="208dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dip"
        android:background="@drawable/splash_facebook_button_selector"
        android:text="Sign up with Facebook" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

自由如风 2024-12-19 17:51:19

在我看来,它并没有将图像视为 9 补丁。您是否使用 .9.png 扩展名保存它?

编辑:
更好地查看实际图像,我认为您没有正确设置它。底部和右边框定义内容的去向(在这种情况下,您希望它位于右侧,并带有一些填充)。
顶部和左侧定义了图像缩放时将拉伸的区域。在这种情况下,您希望它是被拉伸的恒定蓝色区域,而不是徽标。我已经用如何执行此操作的示例更新了图像:

Updated 9-patch

这对我有用!

Looks to me like it's not treating the image as a 9-patch. Have you saved it with the .9.png extension?

Edit:
Had a better look at the actual image and I don't think you've quite got it set up correctly. The bottom and right border define where the content will go (in this case you want it over to the right, with a bit of padding).
The top and left define the areas that will be stretched when the image is scaled. In this case you want it to be areas of constant blue that get stretched, rather than the logo. I've updated the image with an example of how to do this:

Updated 9-patch

This works for me!

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