Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the margin of a EditText using xml?

Hi all I have created layout using following code

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TableLayout android:layout_width="match_parent" android:id="@+id/tableLayout1" android:layout_height="wrap_content">
        <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <TextView android:text="TextView" android:id="@+id/textView1" 
            android:layout_width="wrap_content" android:padding="10dip"


             android:layout_height="wrap_content"></TextView>
            <EditText android:layout_height="wrap_content"
            android:padding="12dip"  android:layout_width="wrap_content" android:text="EditText" android:id="@+id/editText1"></EditText>
        </TableRow>
    </TableLayout>
    <TableRow android:layout_width="match_parent" android:id="@+id/tableRow2" android:layout_height="wrap_content">
        <TextView android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView2"></TextView>
        <EditText android:text="EditText" android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
    </TableRow>
    <TableRow android:layout_width="match_parent" android:id="@+id/tableRow3" android:layout_height="wrap_content">
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>
</LinearLayout>

but now I want to set the margin. How can I do this using XML?

like image 452
mobile.jugnu Avatar asked Jul 03 '11 06:07

mobile.jugnu


2 Answers

Try this for left margin the second one in similar:

<EditText 
    android:id="@+id/editText1"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" 
    android:layout_marginLeft="15dp"
    android:padding="12dp"  
    android:text="EditText" > 
</EditText>
like image 145
gregory561 Avatar answered Sep 28 '22 07:09

gregory561


Try this for Right_margin

android:layout_marginRight = "15dip"

Try this for left margin

android:layout_marginLeft = "15dip"

if you give value in center

android:gravity = "center_horizontal"
like image 20
Rajesh Sharma Avatar answered Sep 28 '22 07:09

Rajesh Sharma