Android 9 补丁图像按钮未按预期缩放
我正在尝试使用 9-patch 技术来创建按钮。
它在 Eclipse 的布局窗口中看起来几乎很棒
当我运行它时在模拟器中它显示如下:
这是实际的 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
When I run it in the emulator it shows up like this:
Here is the actual PNG image
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,它并没有将图像视为 9 补丁。您是否使用 .9.png 扩展名保存它?
编辑:
更好地查看实际图像,我认为您没有正确设置它。底部和右边框定义内容的去向(在这种情况下,您希望它位于右侧,并带有一些填充)。
顶部和左侧定义了图像缩放时将拉伸的区域。在这种情况下,您希望它是被拉伸的恒定蓝色区域,而不是徽标。我已经用如何执行此操作的示例更新了图像:
这对我有用!
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:
This works for me!