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>
<EditT开发者_如何学Cext 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?
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>
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"
Android guidelines now suggest to use marginStart and marginEnd instead of left and right, so:
android:layout_marginStart = "15dp"
If you are using android:drawableLeft you have to use
android:drawablePadding="5dp"
精彩评论