Androidアプリのレイアウトに関して奇妙な問題があります(私はそれを学んでいるので、もちろん電卓を作っています:))。すべてのボタンを行の幅の25%に指定しましたが、上部にEditTextを追加すると、最初の列が他の3つの列よりもはるかに広くなります。(スクリーンショットはIntelliJプレビューのものですが、デバイスにアプリをロードすると同じ結果が表示されます。
EditTextを削除すると、この問題は解消されます。XMLのEditTextに重み属性を追加しようとしましたが、役に立ちませんでした。
結果:
私のコード:
<?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>