0

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>
4

1 に答える 1

1

編集テキストが画面の幅全体に表示される場合は、テーブルの外に配置してみませんか?このような?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">
    <EditText android:layout_width="fill_parent"
              android:layout_height="wrap_content"
                      android:text="Edit me"/>
    <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">
            ...
于 2012-04-19T14:22:46.217 に答える