0

I'm wondering how to create something like the image below using drawables so I can apply it as background?

enter image description here

This isn't a simple rectangle with rounded corners but a kind of a rectangular oval,

Attempts:

Using a rectangle:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#FFFFFF"/>

    <size android:width="40dp"
          android:height="10dp" />

    <corners
        android:radius="100dp" />


enter image description here

Using an oval:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid android:color="#FFFFFF"/>

    <size android:width="40dp"
          android:height="10dp" />

enter image description here

Nima
  • 6,383
  • 7
  • 46
  • 68
  • you need to use shape – SilentKiller Aug 01 '14 at 12:09
  • Why would you close my question? I've already checked the other questions but those are quite different as the corners do not meet like this one. – Nima Aug 01 '14 at 12:13
  • its just kinda of Rounded Corners' TextView.. and there are several samples available – SilentKiller Aug 01 '14 at 12:14
  • I know that it's kind of rounded corners, but this kind of rounded corners aren't possible to be created with corners and paddings as far as i know. – Nima Aug 01 '14 at 12:20
  • and why would you downvote? – Nima Aug 01 '14 at 12:23
  • Added what I've tried – Nima Aug 01 '14 at 12:38
  • to me it seems to be like a custom textview created using nine patch image which is applied to all textview present in application using style – Rajen Raiyarela Aug 01 '14 at 12:55
  • 1
    i think its a rectangle with rounded corners such that *radius of corner circle* = *height of textview /2* – Deepak Negi Aug 02 '14 at 06:44
  • Without a mathematical description of "a kind of a rectangular oval", I'm not sure how you're going to get a really solid answer. Off the cuff, I agree that it is a rounded rectangle, and you need to increase the corner radius until you're happy with it. You could also do it as a nine-patch PNG. – CommonsWare Aug 02 '14 at 12:54

1 Answers1

4

I think for this you have to change the size of text view, By using the below code I got the result.

Code used in Drawable...

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">

    <solid android:color="#ff2233"/>

    <corners
        android:radius="100dp" />

</shape>

Code used in button...

<Button
        android:id="@+id/btn_click"
        android:layout_width="90dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="16dp"
        android:background="@drawable/sh"
        android:text="Click" />

Result: ..........

enter image description here

Remees M Syde
  • 2,564
  • 1
  • 19
  • 42
  • 1
    I think it would be a bad idea to set the width and height explicitly. – Nima Aug 02 '14 at 12:28
  • No need of that,You can set the width and height drawable itself, In text view Make it as wrap_content. Your width and height should maintain a Ratio. – Remees M Syde Aug 02 '14 at 12:38
  • 1
    Seems to be working, added some extra padding to left and right – Nima Aug 03 '14 at 16:08