To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1".
两个 weight 就是大小比值,设成相同就是一样大。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/row_tax"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/row_income"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
1)android:layout_width="fill_parent",不能用wrap_content。
2)android:layout_width="wrap_content",不必改成0dp。这0dp,相当于宽度写成0像素,没必要,反而容易给人误解。<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/row_tax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/row_income"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/row_tax"
android:layout_width="match_content"
android:layout_height="match_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/row_income"
android:layout_width="match_content"
android:layout_height="match_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>1:1 怎么玩都行
alignparentLeft
alignparentRight
<LinearLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/income" >
</TextView>
<EditText
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:id="@+id/income"
android:numeric="integer" >
</EditText>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/insurance" >
</TextView>
<EditText
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:id="@+id/insurance"
android:numeric="integer" >
</EditText>
</TableRow>
</TableLayout>
<Button
android:layout_height="wrap_content"
android:text="@string/pit_btn"
android:layout_width="fill_parent"
android:id="@+id/submit">
</Button>
<TextView
android:id="@+id/result"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/purincome">
</TextView>
</LinearLayout>
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1".
width 设置成0dp
注:设置成0dp可以提高效率,至少谷歌是这么说的。width如果分别设置成不同的值,同时weight设置1,它们的宽度会按照比例进行分配。
好像是TextView 的宽度比等于 各自(weight×width)的比值。
没测试过,看到问题回忆好像是这个样子!!希望对你有用!