角半径 Android 出现问题 [英] Something's wrong in Corner radius Android

本文介绍了角半径 Android 出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Android 2.3 创建自己的搜索视图.

I'm making my own search view for Android 2.3.

我有.

  • LinearLayout(水平)
  • AutoCompleteTextView
  • ImageButton

我将按钮和 AutoCompleteTextView 添加到 LinearLayout.

I added the button and AutoCompleteTextView to LinearLayout.

我想在我自己的控件中放置一个圆角半径,如下图所示.

I want to put a corner radius in my own control like the image shown below.

我将此 drawable 设置为 ImageButton

I set this drawable to ImageButton

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:state_pressed="true" >
    <shape>
        <solid
            android:color="#27AFE0" />
        <stroke
            android:width="0.5dp"
            android:color="#000000" />
        <corners
            android:topRightRadius="10dp" android:bottomRightRadius="10dp"
android:topLeftRadius="0.1dp"
            android:bottomLeftRadius="0.1dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
</item>
<item>
    <shape>
        <solid android:color="#D3DBDE"/>
        <stroke
            android:width="0.5dp"
            android:color="#000000" />
        <corners
            android:topRightRadius="10dp" android:bottomRightRadius="10dp"
android:topLeftRadius="0.1dp"
            android:bottomLeftRadius="0.1dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
</item>

可绘制到 AutoCompleteText

drawable to AutoCompleteText

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="#D3DBDE"/>
        <stroke android:width="0.5dp" android:color="#000000"/>
        <corners android:topLeftRadius="10dp"
            android:bottomLeftRadius="10dp"
            android:topRightRadius="0.1dp"
            android:bottomRightRadius="0.1dp"/>
    </shape>
</item>

但是当我在 android 2.3 中运行它时,这是输出(模拟器和真实设备)

But when I run this in android 2.3 this is the output (Emulator and Real Device)

如果我也在 Android 4.0 中运行.它工作正常.

If I run also in Android 4.0 . It works fine.

问题是,我的代码有什么问题?还是 Android 2.3 有问题?

Question is, what's wrong in my code? Or There's bug in Android 2.3?

推荐答案

好的,这也是让我满意的交易.这有两件事.

Ok so here is the deal this ticked me off as well. There are 2 things with this.

在您的 ImageButton 选择器中,您似乎在每个角标记中复制了右角的属性两次.

In your ImageButton Selector, you seemed to copy the attributes for the right corners twice in each corner tag.

第二个是Android 3.0 之前的一个bug.单独指定角时,左下角和右下角会翻转.

The second is a bug in android up until version 3.0. When specifying the corners separately, the bottom left and right corners get flipped.

http://code.google.com/p/android/问题/详细信息?id=9161

我已将值提取到维度并将它们放在两个不同的文件中,

I have extracted the values out to dimens and put them in two different files,

res/values/corners.xml - 与相反的东西

res/values/corners.xml - with the reversed stuff

res/values-v12/corners.xml - 其中包含合理的值.

res/values-v12/corners.xml - with the sane values in them.

这篇关于角半径 Android 出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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