Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comical bug in Android xml shape declaration

I was creating a shape to use as a button background. I'm making a strip of buttons, and the one on the left edge is going to have rounded corners on the left, and the last one on the right will have rounded corners on the right. This is pretty simple, and the api docs show you just how to do it. However, when I used android:topLeftRadius and android:bottomLeftRadius, the result in the UI was as if I put bottomRightRadius. The same behavior was true of the other side. It appears that whoever implemented this swapped bottomRight and bottomLeft. I'll post a snippet of the code below.

Is there some logical reason for this that I might be missing? Or, if this was a mistake on the part of the Android engineers, will it stay backward compatible once they fix it? I imagine they'd have to make all new attributes to keep the old ones valid (leftTop instead of topLeft maybe?).

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid android:color="#99000000" />
            <padding
                android:top="8dp"
                android:left="8dp"
                android:right="8dp"
                android:bottom="8dp" />
            <corners
                android:topLeftRadius="8dp"
                android:bottomRightRadius="8dp" />
        </shape>
    </item>
like image 479
Rich Avatar asked Dec 07 '10 17:12

Rich


3 Answers

Looks like a bug, see this issue and this question.

like image 54
Donut Avatar answered Oct 02 '22 20:10

Donut


I can't seem to find it, but I recall reading somewhere that there was a bug that required you to first override the full radius, then set back the ones that you don't want to have a radius; for example:

<corners
    android:radius="8dp"
    android:topRightRadius="0dp"
    android:bottomLeftRadius="0dp"
    />

I don't guarantee success, but you may give that a try.

EDIT: Ah, Donut seems to have the right answer.

like image 35
Kevin Coppock Avatar answered Oct 02 '22 18:10

Kevin Coppock


<corners android:topLeftRadius="0.1dp" 
android:topRightRadius="6dp" 
android:bottomRightRadius="0.1dp" 
android:bottomLeftRadius="6px" />

This will work for toleft and top right. adjust it with your requirement

like image 36
Asad Rao Avatar answered Oct 02 '22 18:10

Asad Rao