对于API< 23而言,Android drawable似乎是拉伸的,对于API 23及更高版本,它是正确拉伸的 [英] Android drawable appears stretched for API <23 and correctly for API 23 and above

查看:164
本文介绍了对于API< 23而言,Android drawable似乎是拉伸的,对于API 23及更高版本,它是正确拉伸的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在为列表视图使用列表选择器,并使用layer-list创建了它.这是我的xml代码:

I am currently using a list selector for my listview and created it using layer-list. This is my xml code:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/menu_arrow"
    android:width="18dp"
    android:height="36dp"
    android:top="5dp"/>

<item android:top="0dp" android:left="5dp" android:bottom="0dp" android:right="0dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/transparent"/>
    </shape>
</item>

当我构建应用程序时,它在api 23及更高版本上看起来不错.

When i build the app, it appears fine on api 23 and above.

但是对于api 22及以下版本,它看起来像这样:

But for api 22 and below, it looks like this:

我碰到了这篇帖子 Shape drawable在23以下版本的API中错误地呈现了层列表中的内容,并且了解到width和height属性仅对api 23以上版本有效.所以我在size标签内添加了宽度和高度,如下所示:

I came across this post Shape drawable in layer-list rendered incorrectly for APIs below 23 and understood that the attributes width and height work only for api 23 and above. So i added the width and height inside the size tag like this :

 <item android:drawable="@drawable/menu_arrow"
    android:top="5dp">
    <size android:height="36dp" android:width="18dp"/>
    </item>

但是图像仍然显得拉长.api 22及以下版本需要什么属性才能使所有版本的可绘制外观统一?

But the image still appears stretched. What attribute is needed for api 22 and below to make the drawable look uniform for all the versions?

推荐答案

我设法通过以下方式解决它:

I managed to solve it in the following way :

<item android:drawable ="@drawable/menu_arrow"
    android:right="285dp"
    android:top="5dp"
    android:bottom="10dp"/>

我猜是api<23我们需要使用top,right,bottom值来调整drawable的大小,对于api> 23,我们可以使用width和height.

I guess for api < 23 we need to resize the drawable using top,right,bottom values and for api > 23 we can use width and height.

这篇关于对于API&lt; 23而言,Android drawable似乎是拉伸的,对于API 23及更高版本,它是正确拉伸的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆