简体   繁体   English

Android 9修补程序图像按钮未按预期缩放

[英]Android 9-patch Image Button not scaling as intended

I am trying to use the 9-patch technique to create the button. 我正在尝试使用9-patch技术来创建按钮。

It looks almost great in the Layout Window of Eclipse 在Eclipse的Layout窗口中看起来几乎很棒

Eclipse布局

When I run it in the emulator it shows up like this: 当我在模拟器中运行它时,它显示如下:

仿真器视图

Here is the actual PNG image 这是实际的PNG图片

实际的PNG

Selector XML 选择器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" />

Looks to me like it's not treating the image as a 9-patch. 在我看来,它不是将图像视为9补丁。 Have you saved it with the .9.png extension? 您是否以.9.png扩展名保存了它?

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: 我已通过执行此操作的示例更新了图像:

更新了9补丁

This works for me! 这对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM