Home Forum
Welcome, Guest
Username Password: Remember me

Round Corners
(1 viewing) (1) Guest
Discussion related to creating Android software
  • Page:
  • 1

TOPIC: Round Corners

Round Corners 2 years, 9 months ago #173

Took me a while to figure this out, Its not easy to find a path to the right information in the android documentation (at least for me).

All I wanted to do was draw some round corners on a background using a style, to do this apply a style to the view you wish to have the round corners style="@style/CellHead" in the style set the background to a drawable like this

<item name="android:background">@drawable/cellheader</item>


the drawable should have a corners element, this allows you to define the radius of each corner.

<shape 
xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:bottomRightRadius="0.1dp"
android:bottomLeftRadius="0.1dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
<gradient
android:startColor="@color/celltop" android:endColor="@android:color/white"
android:angle="270" />
</shape>
  • marvin
  • OFFLINE
  • Professor
  • Posts: 18
  • Karma: 0

Re:Round Corners 2 years, 9 months ago #174

A little curiosity in the corners element of <shape> is that the the radius attributes do not seem to correspond to the logical corners, specifically the bottom left corners are transposed, for example the following xml was used to round the two right hand corners of a shape:

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


As you can see the bottom left attribute is set to 6px yet the bottom right corner is rounded.

Another oddity is that you cannot set any corner to 0dp, if you do then non of the corners are rounded.

Do these seem like crazy little bugs, or am I going mad?
  • marvin
  • OFFLINE
  • Professor
  • Posts: 18
  • Karma: 0
  • Page:
  • 1
Time to create page: 0.36 seconds
Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 24 guests online