Daniel MacLeod
Daniel MacLeod

Reputation: 23

How to give layout rounded corners Android

I am trying to display an activity with a translucent background on top of another with a drawable in the center of the screen. The drawable has rounded corners, and I've set a rectangle shape with rounded corners as the background of the layout. The shape has the drawable as it's background. The problem is I still get a black square border behind the round-cornered drawable. Any way to get rid of that black border?

I guess I can't post a picture because I don't have reputation?

Here is the xml for the layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_toast_layout_id"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:orientation="horizontal"
    android:padding="5dp"   
    android:gravity="center"
    android:background="@drawable/myshape" >


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello"
        android:textColor="#000000"
        android:textSize="30sp" />


</RelativeLayout>

Here is the xml for the shape:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/blank_colordots_test">
        <shape android:shape="rectangle" android:padding="10dp">             
            <corners
                android:bottomRightRadius="35dp"
                android:bottomLeftRadius="35dp"
                android:topLeftRadius="35dp"
                android:topRightRadius="35dp"/>
        </shape>
    </item>
</layer-list>

Upvotes: 0

Views: 1275

Answers (3)

Ravi Kishan Nag
Ravi Kishan Nag

Reputation: 19

GradientDrawable border = new GradientDrawable();
    border.setColor(Color.rgb(255,255,255));
    border.setStroke(8, Color.red);
    border.setCornerRadius(20);
    yourview.setBackground(border);

You can try above code to give border to your layout. you can change corner radius and colors as per you requirement. i have used red color as border

Upvotes: -1

V&#237;ctor Albertos
V&#237;ctor Albertos

Reputation: 8293

This should suit your requirements:

//Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:background="@drawable/myshape"
    android:gravity="center">


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello"
        android:textColor="#000000"
        android:textSize="30sp" />

</RelativeLayout>

//Shape:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp">
        <shape android:shape="rectangle">
            <solid android:color="#000000" />
            <corners android:radius="4dp" />
            <stroke
                android:width="1dp"
                android:color="#000000" />
        </shape>
    </item>
</layer-list>

Upvotes: 0

KOTIOS
KOTIOS

Reputation: 11194

Try this code :

rounded_drawable.xml

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

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

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

    <stroke
        android:width="3dp"
        android:color="#ffffff" />

    <padding
        android:bottom="6dp"
        android:left="6dp"
        android:right="6dp"
        android:top="3dp" />

</shape>

Declare this style :

  <style name="ThemeWithCorners" parent="android:Theme.Dialog">

          <item name="android:windowNoTitle">true</item>
    </style>

Apply this style in manifest.

Upvotes: 2

Related Questions