Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border for the layout

I am trying to make a border around my layout like this

two text areas with rounded borders

But what i am trying just change the layout color. Not make any border.

My code is

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"
> 

<stroke android:width="1dp"

        android:color="#eedfcc"
        android:background="#000080"/>

<corners android:bottomRightRadius="20dp"
         android:bottomLeftRadius="20dp" 
         android:topLeftRadius="10dp"
         android:topRightRadius="8dp"/> 
</shape>

Why it does not work out?

like image 259
MBMJ Avatar asked Jul 03 '12 06:07

MBMJ


People also ask

How do you make a layout border?

To insert a simple border graphic around the whole layout (page), use the Insert > Graphics and Text option, selecting Rectangle. Once you've drawn it, you can change the properties to make it hollow (No Fill) and the outline to suit your border requirements.

How do you put a border on android?

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.

What is linear layout?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.

What is relative layout and linear layout?

Android Layout TypesLinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.


2 Answers

try this:

STEP 1 : Create the file layout_border.xml in your project's drawables directory (res/drawable/layout_border.xml) :

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="3dip" android:color="#B1BCBE" />
    <corners android:radius="10dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

STEP 2:

<EditText 
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/layout_border"
     /> 
like image 194
ρяσѕρєя K Avatar answered Oct 10 '22 13:10

ρяσѕρєя K


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" />
    <solid android:color="#ffffff" />
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
</shape>

Then add this as a background inside your layout tag:

android:background="@drawable/my_border"
like image 26
Erol Avatar answered Oct 10 '22 15:10

Erol