Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to put a border around an android relativelayout?

Tags:

I've seen this subject about puting a border around an android textview, and I used it. But now, I would like to put a border around widgets which are situated into a relative layout. How can I do it?

like image 716
AyaAndro Avatar asked May 03 '12 11:05

AyaAndro


People also ask

How do I put a border around an android TextView?

To add a border to Android TextView we need to create an XML containing shape as a rectangle file under the drawable's folder and set it as background to the TextView. <stroke> tag is used to set the border width and color.

How do I add a border to relative layout?

Create a FrameLayout that gets the background color of your border, and a margin or padding of your border width, and place that FrameLayout in your RelativeLayout. Place the TextView in your FrameLayout instead of directly in the RelativeLayout. poof instant border. Show activity on this post.

How do you add a border on Kotlin?

Create an Android Application with Kotlin support and Empty Activity. Right click on res/drawable folder and click on New -> Drawable Resource File. Give file name as border(or any other name) and Root element as shape. border.

How do I change the layout border color?

Select the table cells that you want to add a border to (or change the border of). Select the Table Tools / Design tab on the ribbon. Select one of the following in the Draw Borders group: Use Pen Color to change the color of the border.


1 Answers

  1. in your res/drawable folder, create a new file background_border.xml

In this file, you will define the background for widget like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android"        android:shape="rectangle" >     <!-- This is the stroke you want to define -->     <stroke android:width="1dp"              android:color="@color/color_stroke"/>      <!-- Optional, round your corners -->     <corners android:bottomLeftRadius="0dp"              android:topLeftRadius="5dp"              android:bottomRightRadius="5dp"              android:topRightRadius="0dp" />      <!-- Optional, fill the rest of your background with a color or gradient, use transparent if you only want the border to be displayed-->     <gradient android:startColor="@android:color/transparent"               android:endColor="@android:color/transparent"               android:angle="90"/> </shape> 
  1. set the background of your widget to the drawable configuration you've just created

eg. if you want to put your border on a relativelayout:

<RelativeLayout                         android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="@drawable/background_border"             android:padding="15dp">     ... </RelativeLayout> 
like image 167
RWIL Avatar answered Nov 12 '22 23:11

RWIL