Sponser

create your own banner at mybannermaker.com!

Monday, July 11, 2011

Design a linearlayout or textview and any component in android with border,corner radius and gradient

We can design a linearlayout or relativelayout or framelayout... or even we can design a text view with this coding. The sample is given for linear layout, the result will be like this

here i had given corner radius for left top corner and left bottom corner for the linear layout, and i applied border for whole linearlayout.

For design the layout we need to use this xml file


layout_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="2dp" android:height="2dp"
android:color="#FF0000" />
<solid android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />

<corners android:radius="1dp" android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp" android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>

</layer-list>


and we need to set the xml file as background for the linear layout as


In the main xml
<LinearLayout android:layout_gravity="center"
android:layout_width="200dp" android:layout_height="200dp" android:background="@drawable/layout_border" />


For gradient effect you can use the below xml, this will not be in the source, you can put this file and set this as background for gradient effect


layout_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#ffa5ba"
android:endColor="#ff92af"
android:angle="150"/>

</shape>


The code is fulling checked so you can run the code after downloading it itself.

You can download the full source code


Download source


Have a good day.

2 comments:

  1. Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.
    WINDOWS PHONE 7 DEVELOPMENT| Android developer|

    ReplyDelete

Sponser