Wednesday, January 4, 2012

Android: Rounded Border with Gradient

Have a custom_rounded.xml in drawable folder.

have a code snippet:

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

    <gradient
        android:angle="270"
        android:endColor="@color/gray"
        android:startColor="@color/white" />

    <corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />

</shape>

add the drawable file in your layout as follows:

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="139dp"
        android:background="@drawable/custom_rounded" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    </LinearLayout>

Output:





No comments :

Post a Comment