As an Android drawable, this represents a black rectangle with rounded corners.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="#000000" />
</shape>
However, the corner radius is specified as an absolute 20dp
, so if this same drawable is shown at different sizes, it appears differently. The smaller shape is not just a "scaled down" version of the larger one. Instead, it's "rounder" and the larger one is "more square" because the border radius is a static 20dp
regardless of the size of the drawable.
I want to specify the radius relative to the size of the full drawable, so when it is drawn at different sizes each one appears as a scaled up/down version of the others.
I'm more familiar with CSS, where this can be done in one line:
border-radius: 20%;
I'm surprised to find Android lacking this CSS simplicity. Android does not recognize %
as a unit.
<corners android:radius="20%" />
Is there some simple way to achieve my desired result in Android?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…