处理形状绘制不同的Andr​​oid 2.3.5 VS 4.0的最佳方式 [英] Best way to handle shape drawable differences Android 2.3.5 vs 4.0

查看:130
本文介绍了处理形状绘制不同的Andr​​oid 2.3.5 VS 4.0的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的形状绘制这个形状:

I'm trying to have a shape drawable with this shape:

这使用以下时,正常工作在1.6到2.3.5:

This works properly in 1.6 to 2.3.5 when using the following:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle"> 
<solid android:color="#cc6900"/>

<corners android:radius="0.1dp" android:bottomRightRadius="7dp" android:bottomLeftRadius="0dp"
 android:topLeftRadius="0dp" android:topRightRadius="7dp"/> 

然而,在Galaxy Nexus的,或4.0模拟器上运行时,我不得不使用它来获取相同的布局:

However, when running it on a Galaxy Nexus, or a 4.0 Emulator, I have to use this to get the same layout:

...
<corners android:radius="0.1dp" android:bottomRightRadius="0dp" android:bottomLeftRadius="7dp"
 android:topLeftRadius="0dp" android:topRightRadius="7dp"/> 
...

这给了我这个在1.6:

Which gives me this on 1.6:

因此​​,基本上,previous版本都采用bottomRight和BOTTOMLEFT的一种方式,而现在4.0做它在另一个。

So basically, previous versions has all used bottomRight and bottomLeft in one way, and now 4.0 does it in another.

有没有办法,我可以把它像它是pre 4.0,并给予4.0用户改变的值没有简单的方法?如果可能的话,我想preFER如果我能保持它在XML,而不是有它在code。

Is there any easy way that I can have it be like it is for pre 4.0, and give 4.0 users the changed values? If possible, I'd prefer if I could keep it in XML and not have it in code.

推荐答案

嗯,貌似我们打破了错误的兼容性,当我们固定的那一个。 ;)

Hm, looks like we broke bug compatibility when we fixed that one. ;)

既然你确定这在一个XML绘制,包括Android 4.0的前的工作版本的 RES /绘制/ 目录和一个在Android 4.0的作品+在所谓的另一个目录 RES /绘制-V14 / 。 (14的是Android 4.0的API级别。)运行Android 4.0及更高版本的设备将使用新的版本。

Since you're defining this in an XML drawable, include the version that works before Android 4.0 in your res/drawable/ directory and the one that works on Android 4.0+ in another directory called res/drawable-v14/. (14 is the API level of Android 4.0.) Devices running Android 4.0 and newer will use the newer version.

您可以使用同样的技术可以让系统自动选择正确的资源一堆不同的配置选项,在这里看到的更多信息:<一href="http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources">http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

You can use this same technique to have the system auto-select the correct resource for a bunch of different configuration options, see here for more info: http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

这篇关于处理形状绘制不同的Andr​​oid 2.3.5 VS 4.0的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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