I have a strange problem concerning a layout in my Android app (I m learning it, so ofcourse I m making a calculator :) ). I have specified all the buttons to be 25% of the width of the row, but when I add the EditText at the top, the first column becomes a lot wider than the other three columns. (The screenshot is from the IntelliJ preview, but when I load the app on my devices the same results shows.
当我去除EditText时,这一问题就消失了。 我曾试图在XML中增加EditText的权重,但没有结果。
The result:
我的法典:
<?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="fill_parent">
<TableLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:weightSum="1.0">
<TableRow android:layout_width="fill_parent"
android:weightSum="1.0">
<EditText android:layout_weight="1.0"
android:text="Edit me"></EditText>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:weightSum="1.0">
<Button android:text="7"
android:layout_weight="0.25"></Button>
<Button android:text="8"
android:layout_weight="0.25"></Button>
<Button android:text="9"
android:layout_weight="0.25"></Button>
<Button android:text="/"
android:layout_weight="0.25"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:weightSum="1.0">
<Button android:text="4"
android:layout_weight="0.25"></Button>
<Button android:text="5"
android:layout_weight="0.25"></Button>
<Button android:text="6"
android:layout_weight="0.25"></Button>
<Button android:text="*"
android:layout_weight="0.25"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:weightSum="1.0">
<Button android:text="1"
android:layout_weight="0.25"></Button>
<Button android:text="2"
android:layout_weight="0.25"></Button>
<Button android:text="3"
android:layout_weight="0.25"></Button>
<Button android:text="-"
android:layout_weight="0.25"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent">
<Button android:text="0"
android:layout_weight="0.25"></Button>
<Button android:text="."
android:layout_weight="0.25"></Button>
<Button android:text="+/-"
android:layout_weight="0.25"></Button>
<Button android:text="="
android:layout_weight="0.25"></Button>
</TableRow>
</TableLayout>
</LinearLayout>