【问题标题】:XML drawable having different behavior on 4.3 and 4.1.2XML drawable 在 4.3 和 4.1.2 上具有不同的行为
【发布时间】:2013-09-22 01:27:04
【问题描述】:

我有以下可绘制对象,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="3dp"/>
    <padding android:left="1dp" android:right="1dp" android:top="1dp" android:bottom="1dp"/>
     <stroke android:width="1dp" android:color="#e4e4e4"/>

</shape>

“它应该”在背景设置时绘制边框,实际上在 (Android 4.3 /goole nexus 7) 上确实如此,但不幸的是在 (Android 4.1.2/三星 Galaxy Tab 10") 上它只是填充了所有背景用颜色

如果有人能告诉我我做错了什么,或者如果有人有一个可绘制的 xml 边框, 我会非常感激:=)

【问题讨论】:

  • 将内边距增加到5dp试试
  • Ichanged the padding with the following: 但我有同样的问题
  • 我刚试过,它对我有用。我只是将填充更改为 5p。增加你的填充并尝试。我在手机而不是平板电脑上测试过
  • 奇怪 :( 对我来说,即使我完全删除了填充线,我也有这个问题,谢谢
  • 我终于找到了一个更好的drawable我把它作为答案:)

标签: android android-drawable xml-drawable


【解决方案1】:

这是具有相同drawable的解决方案

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <corners android:radius="3dp"/>
    <stroke android:width="1dip" android:color="#e2e2e2"/>
</shape>

我只需要指定纯色:

 <solid android:color="@android:color/transparent" />

【讨论】:

    【解决方案2】:

    在两个版本上效果更好的边框可绘制代码:

    <?xml version="1.0" encoding="utf-8"?>
    
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- This is the line -->
        <item android:top="1px" android:right="1px" android:left="1px" android:bottom="1px">
          <shape>
                <solid android:color="@android:color/transparent" />
                <corners android:radius="3dp"/>
                <stroke android:width="1px" android:color="#e4e4e4" />
          </shape>
        </item>
    
    </layer-list>
    

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多