【问题标题】:bug in android 2.1 xml drawables?android 2.1 xml drawables 中的错误?
【发布时间】:2010-07-23 13:41:07
【问题描述】:

看下图,左边的按钮是android 2.1,右边的是2.2:

如您所见,左侧图像上的角没有正确应用,但它们在 2.2 中看起来很完美。我正在使用的 xml 在这里:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="0dip" android:left="0dip" android:bottom="0dip"
    android:top="0dip">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:bottomRightRadius="3dip"
            android:bottomLeftRadius="3dip" android:topLeftRadius="3dip"
            android:topRightRadius="3dip" />
        <stroke android:width="1dip" android:color="#70532B" />
        <padding android:left="1dip" android:top="1dip"
            android:right="1dip" android:bottom="1dip" />
    </shape>
</item>
<item android:right="0dip" android:left="0dip" android:bottom="0dip"
    android:top="9dip">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#ECAF08" android:endColor="#F6E34B"
            android:angle="270" />
        <corners android:bottomRightRadius="3dip"
            android:bottomLeftRadius="3dip" android:topLeftRadius="0dip"
            android:topRightRadius="0dip" />

    </shape>



</item>
<item android:right="0dip" android:left="0dip" android:bottom="11dip"
    android:top="0dip">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#FCEF94" android:endColor="#FFBA00"
            android:angle="270" />
        <corners android:bottomRightRadius="0dip"
            android:bottomLeftRadius="0dip" android:topLeftRadius="3dip"
            android:topRightRadius="3dip" />
    </shape>
</item>

我做错了什么,或者这是 android 2.1 中的错误???

【问题讨论】:

    标签: android xml drawable


    【解决方案1】:

    制作渐变按钮的巧妙方法。

    我想知道这是否与 &lt;corners&gt; xml 在 Android 2.1 及更低版本中存在错误有关。 bottomLeftRadius 实际上对应于 bottomRightRadius,反之亦然。他们可能已经在 2.2 中修复了它,因此它在 2.2 中看起来是正确的,但是在 2.1 及更低版本中您以意想不到的方式重叠。如果是这种情况,您可以使用以版本为目标的文件夹为每个版本使用不同的可绘制对象(又名/drawable-v7//drawable-v8/)。

    【讨论】:

    • 所以问题是你似乎不能有一个顶部有角而底部没有角的矩形。我以前见过这个问题。上次我遇到它时,我找到了一种解决方法,基本上是在有角矩形的顶部覆盖一个矩形,从而将底部暴露为有角的,而顶部保持平坦。它很老套,但很有效。
    • 另一件有点烦人的事情是你不能使用相对尺寸?即在我上面的例子中,你可能注意到我分别有 11 和 9 次下降。使用 51% 和 49% 或类似的东西肯定会很好......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 2021-08-02
    • 2015-11-19
    相关资源
    最近更新 更多