Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: drawable with perfect round corner

I'm trying to make a drawable like belowenter image description here:

I've made this by the following code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/white"
    android:padding="10dp"
    android:orientation="vertical">

<View
    android:layout_width="40dp"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/bg_round_button_green"/>

<View
    android:layout_width="40dp"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:background="@drawable/bg_round_button_green"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="36dp"
    android:text="Text"
    android:textColor="@color/white"
    android:textSize="22sp"
    android:gravity="center"
    android:layout_centerVertical="true"
    android:background="@color/siam_green3"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"/>

</RelativeLayout>  

bg_round_button_green.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring">
    <solid android:color="#FF0DAB61"/>
</shape>  

I also tried this:
bg_round_button_green.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FF0DAB61"/>
    <corners android:radius="100dp"/>
</shape>  

But it displays,
enter image description here

Is it possible to do this with a single shape drawable (without creating three Views) ?

like image 294
palatok Avatar asked Feb 19 '15 15:02

palatok


People also ask

How do I make a round corner image in Android?

Android Round Corner ImageView. Making round corners on the image by using a mask Put an ImageView and a mask view in a RelativeLayout. Make the mask view round corners and put it on top of the ImageView. The layout: Apply round corner image transformation when loading the image through Picasso. The round corner transformation class.

How do I apply a rounded corner to a linearlayout?

To apply the rounded corner to a LinearLayout (or Relative, Frame, etc) you will need to set the XML Drawable to the background property of the layout as shown below.

How do I draw a rounded rectangle using roundeddrawable?

The drawable set by the setDrawable (Drawable) method will be drawn within the rounded bounds specified by Drawable.setBounds (Rect) and setRadius (int) when the draw (Canvas) method is called. By default, RoundedDrawable will apply padding to the drawable inside to fit the drawable into the rounded rectangle.

How to make round corners on the image using a mask?

Making round corners on the image by using a mask Put an ImageView and a mask view in a RelativeLayout. Make the mask view round corners and put it on top of the ImageView.


1 Answers

Try this. Works perfectly for me.

<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#A5000000"/>
    <stroke android:width="0dp"
      android:color="#00FFFFFF"/>
    <padding android:left="0dp"
      android:top="0dp"
      android:right="0dp"
      android:bottom="0dp"/>
    <corners android:bottomRightRadius="10dp"
      android:bottomLeftRadius="10dp"
      android:topLeftRadius="10dp"
      android:topRightRadius="10dp"/>
  </shape>
like image 88
Hemanth Avatar answered Sep 27 '22 21:09

Hemanth