Border around a LinearLayout / rounded edges

37450 views
Skip to first unread message

code_android_festival_way

unread,
Jan 27, 2009, 2:32:29 PM1/27/09
to Android Developers
Hello.

I'm not very experienced in Java. Is there an easy possibility to get
a border and round edges around a LinearLayout? (perhaps with XML
parameters)

Or do I have to draw my own widgets.

Thank you for your help.

Regards.

James Yum

unread,
Jan 27, 2009, 6:43:03 PM1/27/09
to android-d...@googlegroups.com
Hi,

You can set the background to a 9-patch image:


It's fairly easy to create one yourself. Just make sure the outside 1-pixel area is completely empty except for the black lines.

Or ...

Create a file "res/drawable/my_border.xml" and define a shape:

    <stroke android:width="4dp" android:color="#FF00FF00" />
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
</shape>

The padding is optional, but you just might need it.

... and then set the layout's background:

<LinearLayout
   android:background="@drawable/my_border"
   ...

Cheers,
James


code_android_festival_way

unread,
Jan 28, 2009, 3:14:04 AM1/28/09
to Android Developers
Thank you very much. That helped me out.

Regards.

On 28 Jan., 00:43, James Yum <j...@google.com> wrote:
> Hi,
> You can set the background to a 9-patch image:
>
> http://code.google.com/android/reference/available-resources.html#nin...
>
> It's fairly easy to create one yourself. Just make sure the outside 1-pixel
> area is completely empty except for the black lines.
>
> Or ...
>
> Create a file "res/drawable/my_border.xml" and define a shape:
>
> <shape xmlns:android="http://schemas.android.com/apk/res/android">
>     <stroke android:width="4dp" android:color="#FF00FF00" />
>     <padding android:left="7dp" android:top="7dp"
>             android:right="7dp" android:bottom="7dp" />
>     <corners android:radius="4dp" />
> </shape>
>
> The padding is optional, but you just might need it.
>
> ... and then set the layout's background:
>
> <LinearLayout
>    android:background="@drawable/my_border"
>    ...
>
> Cheers,
> James
>
> On Tue, Jan 27, 2009 at 11:32 AM, code_android_festival_way <
>

Tyler Collier

unread,
Jul 8, 2011, 6:06:56 PM7/8/11
to android-d...@googlegroups.com
This didn't work for me, but after reading this link on StackOverflow, I saw what was missing: the <solid/> element.  So try:

    <stroke android:width="4dp" android:color="#FF00FF00" />
    <solid android:color="#ffffff" />
Reply all
Reply to author
Forward
0 new messages