2

I have several items I want to display. All the items have a title and subtitle. When I think about it's quite similar to bubbles in WhatsApp or Facebook. I guess these are implemented as 9-patch-drawables.

My background is like a circle and rectangle combined with two TextViews in front.

sample

My approaches:

  • 9-patch-drawables: I can achieve the design, but I have to support several background colors. And images are very inflexible.
  • drawable xml: when I create a drawable I can define an oval or a rectangle with corners as shapes. But the shapes scale. So in fact the circle part on the left is not really round.

Now I had a look at the AnalogClock which really is perfectly round, but it inherits from View and does measuring and painting by code.

So I assume I have to create a control on my own. Or are there any other approaches?

Requirements are:

  • it must not skew, when I change any of the sides, but should scale
  • I must be able to change the background color in code
  • and of course I should be able to set the texts

Any hints for me how to achieve this?

Onik
  • 19,396
  • 14
  • 68
  • 91
Martin H.
  • 1,086
  • 1
  • 17
  • 28

1 Answers1

0

Put this Relativelayout in your .xml

<RelativeLayout
    android:layout_width="220dp"
    android:layout_height="90dp"
    android:background="@drawable/custom_button" >
</RelativeLayout>

custom_button.xml - add it in res > Drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" > 
<corners
android:topLeftRadius="100dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="100dp"
android:bottomRightRadius="0dp"
/>
<solid
android:color="#4F4F4F"
/>
<size
android:width="220dp"
android:height="90dp"
/>
</shape>
Kishan Soni
  • 816
  • 1
  • 6
  • 19