android形状xml显示API 19和21的不同
我得到了如下形状xml:android形状xml显示API 19和21的不同,android,shape,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
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>
drawable/contact\u list\u fastcroll\u bubble.xml
此代码是从AOSP移植的:
在api 21上,它看起来像这样,这就是我想要的api 19
但在api 19上,它看起来不同,这不是我想要的
我想知道:
编辑: 我在两个模拟器上截图,都基于Nexus6p和2560x1440,只是api级别不同
编辑2: 我想解释一下如何测量可拉伸的形状 我使用这种可拉伸材料如下:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:fastScrollPreviewBackgroundRight">@drawable/contact_list_fastscroll_bubble</item>
</style>
@可绘制/联系人列表\u快速滚动\u气泡
其中contact\u list\u fastcroll\u bubble
是上面发布的xml
属性
android:fastScrollPreviewBackgroundRight
设置ListView的fast scroller drawable
。因此,ListView
有责任测量可绘制的图形。开发人员不需要设置可绘制文件的大小。我不确定,但这可能是一个原因。你们的形状是矩形的,你们只是在做圆角,所以这是基于你们的dp反射弧。在api 21(高分辨率设备)中,dp更像是圆形的,但在api 19中,可能您使用的分辨率较低的设备使其成为矩形。看起来圆角在棒棒糖之前计入填充。创建可绘制图形的两个变体
可绘制/联系人列表\u快速滚动\u 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>
drawable-v21/contact_list_fastscroll_bubble.xml
您是如何测试和确认这一点的?它是从AOSP:移植的,标签为android-5.1.1_r37。@gvsharma我在api 19和21的手机上截图。那又如何?你怎么能假设API 21具有高分辨率,而API 19具有低分辨率?你能坚持你的答案吗?谢谢你的回答。我有两个模拟器都基于Nexus 6p和2560x1440,只是api级别不同。你说得对@gvsharma。我们不能假设,但解决方案可能是一个问题。但我不知道他是如何测试的。@Mukesh我已经编辑了我的问题,添加了测试环境。好的。。你怎么能保证矩形的长度是88 dp,因为你给了coner 44,并试图得到一个圆弧,它应该通过矩形边长度的一半。您是否在java中动态设置lengh?
<?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>