Anton Kizema
Anton Kizema

Reputation: 1092

Android Create resizable drawable

I want te creat tab bar with indicators. The problem is i have to do in a circle, if number displayed is <=9, and rounded rect, if number displayed >=10. How would I achieve this?

enter image description here

Upvotes: 0

Views: 173

Answers (1)

Sujay
Sujay

Reputation: 3455

Resizable images are achieved using 9-patch images. Android SDK has 9-patch image creator & exact documentation is available at https://developer.android.com/studio/write/draw9patch.html.

As per doc

Blockquote

The dotted grey lines identify the regions of the image that will be replicated in order to stretch the image. The pink rectangle in the bottom image identifies the region in which the contents of the View are allowed. If the contents don't fit in this region, then the image will be stretched so that they do.

Use a circular png icon & create a 9-patch image to set it as the textview background.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/circle_red"
    android:gravity="center"/>

Upvotes: 1

Related Questions