Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - round rect border for layouts

Tags:

in my application I'm going to use a lot of layout "borders" which are a simple rounded rectangle. To test how it would look like I created a .png file with transparent background:

enter image description here

I just set the image as my layout background. The problem is that I need different proportions for other layouts and that would be a waste of time to create such images in Photoshop for all my layouts.

The questions: how can I do the same with the android API (maybe an XML shape) but allow the rectangle to be stretched to any dimension and still remain sharp?

like image 757
Droidman Avatar asked Jul 21 '13 16:07

Droidman


People also ask

How to make rounded corners android?

xml file and add an attribute to that TextView, for which you want to add rounded corners. The attribute is android: background=”@drawable/rounded_corner_view”.

How to add corner radius in android studio?

Color and corner radius for the button can be modified as per your needs. The changes you make can be seen in the design option in the side: Now , in the main xml file where you want the rounded corners for the button , add this line : android:background=”@drawable/rounded_corner ” .


Video Answer


1 Answers

You can use a drawable

Have bkg.xml in drawable folder

<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"        android:shape="rectangle">     <solid android:color="#FFFFFF"/>     <stroke         android:width="3dp"         android:color="#0FECFF"/>     <padding         android:bottom="5dp"         android:left="5dp"         android:right="5dp"         android:top="5dp"/>     <corners         android:bottomLeftRadius="7dp"         android:bottomRightRadius="7dp"         android:topLeftRadius="7dp"         android:topRightRadius="7dp"/> </shape> 

Then set background

  android:background="@drawable/bkg" //to required view 

Snasp shot of graphical editor when set drawable background to textview.

enter image description here

like image 65
Raghunandan Avatar answered Oct 02 '22 18:10

Raghunandan