Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Apply Corner Radius to LinearLayout

I want to make a layout with a rounded border. How can I apply a radius of a particular size in a LinearLayout?

like image 927
Aamirkhan Avatar asked Apr 09 '12 13:04

Aamirkhan


2 Answers

You can create an XML file in the drawable folder. Call it, for example, shape.xml

In shape.xml:

<shape     xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle"   >          <solid         android:color="#888888" >     </solid>          <stroke         android:width="2dp"         android:color="#C4CDE0" >     </stroke>           <padding         android:left="5dp"         android:top="5dp"         android:right="5dp"         android:bottom="5dp"    >     </padding>           <corners         android:radius="11dp"   >     </corners>       </shape> 

The <corner> tag is for your specific question.

Make changes as required.

And in your whatever_layout_name.xml:

<LinearLayout     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="vertical"     android:layout_margin="5dp"     android:background="@drawable/shape"    > </LinearLayout> 

This is what I usually do in my apps.

like image 54
Siddharth Lele Avatar answered Sep 24 '22 07:09

Siddharth Lele


You would use a Shape Drawable as the layout's background and set its cornerRadius. Check this blog for a detailed tutorial

like image 39
Mirko Lindner Avatar answered Sep 24 '22 07:09

Mirko Lindner