android shape xml对API 19和21显示不同

时间:2016-05-27 06:40:57

标签: android shape

我有一个像这样的形状xml:

drawable/contact_list_fastscroll_bubble.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:topLeftRadius="44dp"
        android:topRightRadius="44dp"
        android:bottomLeftRadius="44dp"/>
    <padding
        android:paddingLeft="22dp"
        android:paddingRight="22dp" />
    <solid android:color="@color/app_color_green"/>
</shape>

此代码从AOSP移植:https://github.com/android/platform_frameworks_base/blob/d3383d5bfab296ba3adbc121ff8a7b542bde4afb/core/res/res/drawable/fastscroll_label_right_material.xml

在api 21上,它看起来像这样,是我想要的api 19。

API 21 但是在api 19上,它看起来不同,并不是我想要的。

API 19 我想知道:

  1. 为什么它改变了形状,
  2. 如何在api 19中获取第一张图片?
  3. 谢谢!

    编辑:

    我在2个仿真器上截取屏幕截图,两者都基于Nexus 6p和2560x1440,只有api级别不同。

    编辑2:

    我想解释一下如何测量形状可绘制。

    我使用这个drawable如下:

    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:fastScrollPreviewBackgroundRight">@drawable/contact_list_fastscroll_bubble</item>
    </style>
    

    其中contact_list_fastscroll_bubble是上面发布的xml。

    属性android:fastScrollPreviewBackgroundRight设置fast scroller drawable的{​​{1}}。所以ListView负责衡量可绘制性。开发人员不需要设置drawable的大小。

2 个答案:

答案 0 :(得分:0)

看起来圆角在Lollipop之前计入填充。创建drawable的两个变体。

抽拉/ contact_list_fastscroll_bubble.xml

没有额外的填充。

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:topLeftRadius="44dp"
        android:topRightRadius="44dp"
        android:bottomLeftRadius="44dp"/>
    <solid android:color="@color/app_color_green"/>
</shape>

绘制-V21 / contact_list_fastscroll_bubble.xml

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:topLeftRadius="44dp"
        android:topRightRadius="44dp"
        android:bottomLeftRadius="44dp"/>
    <padding
        android:paddingLeft="22dp"
        android:paddingRight="22dp" />
    <solid android:color="@color/app_color_green"/>
</shape>

答案 1 :(得分:-1)

我不确定,但这可能是一个原因。你的形状是矩形的,你只是在圆形的角落,所以这是根据你的dp反射弧。在api 21(高分辨率设备)中,dp更像是它的外观圆形,但在api 19中,你可能会使用较少分辨率的设备,因此它会变成矩形。

相关问题