Something's wrong in Corner radius Android

☆樱花仙子☆ 提交于 2019-11-27 15:30:18
Greg Giacovelli

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

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

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/issues/detail?id=9161

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

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

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

There is a bug in earlier versions (earlier than ICS i.e. 4.0) of android, where they have incorrectly implemented 'corners' attribute of 'Shape' class. So, to get the correct kind of corners on all versions, you will have to write a condition which checks the target version and accordingly you can set the correct background. A method something like this will solve your problem -

/** * handling the bug in Pre ICS versions with corner element of Shape class * */

private void getPreICSButtonBackground() {
    if(Build.VERSION.SDK_INT >= 4.0){
        leftButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_rounded_left));
        rightButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_rounded_right));
    }
}

Where in 'R.drawable.btn_rounded_left' corners are implemented like

    <corners android:topLeftRadius="5dp" android:topRightRadius="0dp"
    android:bottomLeftRadius="5dp" android:bottomRightRadius="0dp" />

and if it is running on earlier versions, then set the background having corners as

<corners android:topLeftRadius="5dp" android:topRightRadius="0dp"
    android:bottomLeftRadius="0dp" android:bottomRightRadius="5dp" />

Similarly do for the right side Button. Hope this solves your problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!