Layout design problem
in android i m trying to make a simple form with two buttons.. but i am facing alignment issue. can you please help in that..
here is the code
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns = "1"
>
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="UserName"></TextView>
<EditText android:text="EditText" android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Password"></TextView>
<EditText android:text="EditText" android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</TableRow>
<TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:layout_height="wra开发者_如何学Cp_content" android:layout_width="wrap_content" android:id="@+id/button1" android:text="save"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/button2" android:text="cancel"></Button>
</TableRow>
</TableLayout>
with this code,i am getting UI like this,but i want the buttons to be aligned,please help me
Move the buttons out of the table layout and into a LinearLayout?
<LinearLayout android:id="@+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button1"
android:text="save"
android:layout_weight="1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button2"
android:text="cancel"
android:layout_weight="1"/>
</LinearLayout>
You might have to set both the table and the LinearLayout in a vertical LinearLayout and set weights on them.
精彩评论