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:
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?
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”.
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 ” .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With