2011-02-15 98 views
1

我跟着this tutorial为Android做了一些更好的按钮,我也从该网站上拿了9-patch按钮的例子。它是这一个:enter image description here9-补丁按钮显示不正确

但正如你在下面的图片中看到的,我的按钮显示不正确。

enter image description here

这里是 “4×4” 按钮的代码:

<Button android:id="@+id/btn4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="starteSpiel" 
     android:text=" 4 x 4 " 
     android:background="@drawable/button" /> 

这里是我的button.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_focused="true" 
    android:state_pressed="false" 
    android:drawable="@drawable/button_normal" /> 
<item android:state_focused="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/button_normal" /> 
<item android:state_focused="false" 
     android:state_pressed="true" 
    android:drawable="@drawable/button_normal" /> 
<item android:drawable="@drawable/button_normal" /> 

在哪里错误?按钮应该看起来像tutorial中的那些按钮。

+2

您可能需要将其保存为wtiVz.9.png文件扩展名。 – Jems 2011-02-15 14:35:14

+0

是的,就是这样。谢谢! – Maaalte 2011-02-15 14:44:27

回答

3

尝试通过直接设置在Button/@android:brackground

@drawable/button_normal简化代码通过阅读你的代码,我明白你(在教程文件名)改名为button.9.pngbutton_normal.9.png - 是吗?