Wednesday, 25 April 2012

How To Apply Rounded Corners to Layout in Android

Here below example shows how to set Rounded corners to Layout

Create (round.xml) file in drawable folder of your project
Copy below code:


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

Use this layout as background to Layout
<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="match_parent"
    tools:context=".RoundedCornerEditText"
    android:background="@android:color/darker_gray">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="76dp"
        android:background="@drawable/round" >
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="86dp"
            android:layout_marginTop="156dp"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

</RelativeLayout>

Output Screenshot:










Note: 

Like this u can apply this(round.xml)layout as background to any view.

No comments:

Post a Comment

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...