九个补丁StateListDrawable渲染问题

时间:2011-11-22 19:48:39

标签: android android-layout

从版本12更新为 SDK工具修订版15 后,我的EditTexts和按钮都显示为扭曲...

How it looks now How it used to look

现在这是修订版的错误吗?因为当我使用“图形布局”标签预览布局时,它看起来很正常。但是一旦它被编译并放在我的手机或模拟器上,就会失真。

这是按钮的StateListDrawable xml。在此引用的每个drawable是 9patch 。 EditTexts以相同的方式完成。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_grey_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/button_grey_pressed" android:state_focused="true"></item>
    <item android:drawable="@drawable/button_grey_pressed" android:state_selected="true"></item>
    <item android:drawable="@drawable/button_grey_default"></item>
</selector>

3 个答案:

答案 0 :(得分:2)

这是我在更新到SDK 14时遇到的一个问题。

我在Window>Preferences>Android>Build找到了一个解决方案,方法是在Normal然后Project>Clean>Clean All设置“构建输出”。

答案 1 :(得分:1)

我已经从here复制并粘贴了它并且有效:

  
      
  1. 禁用自动刷新,自动构建。
  2.   
  3. 彻底清理所有项目。
  4.   
  5. 构建所有项目。
  6.   
  7. 清理主项目。
  8.   
  9. 建立主项目。
  10.   

答案 2 :(得分:0)

尝试将这些九个补丁drawable(我想@drawable/button_grey_pressed引用/drawable/button_grey_pressed.9.png)包装成xml九补丁drawable:

<?xml version="1.0" encoding="utf-8"?>
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/button_grey_pressed"
    android:dither="true" />

您必须为此xml文件指定与button_grey_pressed.9.png不同的名称,例如button_grey_pressed9.xml