Reputation: 2582
There are two main approaches for rounded corners on android:
Implement via layout definition, some examples can be found here: How to make layout with rounded corners..?
Implement via 9 patch, which is described here: http://developer.android.com/tools/help/draw9patch.html
What I don't understand is why should I ever prefer using 9 patch instead of layout definition? Is there any benefit for it performance wise or for some other aspect?
Upvotes: 0
Views: 79
Reputation: 54801
I would choose the simplest tool that gives me what I need. Especially knowing I can switch later easily. Xml if simple shape is all I need and 9-patch if I need something more complex or have been supplied an asset to use.
A 9-patch can do far more than simple rounding in an xml shape, it stretches the original asset maintaining the four corners in their aspect ratio, they might be round they might not, they could be as complex as you like.
I should think the performance is not a reason for making either choice in most sensible use cases.
Upvotes: 1
Reputation: 7183
There is also the 3rd option with CardView which is much cleaner and easier to maintain.
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardBackgroundColor="@color/green"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="0dp" >
</android.support.v7.widget.CardView>
Upvotes: 1