-1

我开发了一个应用程序,以下是代码

这是这个应用程序的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeScreen" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="*"
        android:weightSum="4" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/fBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/fStr" />

            <Button
                android:id="@+id/rBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/rStr" />

            <Button
                android:id="@+id/sBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/sStr" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/cBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/cStr" />

            <Button
                android:id="@+id/aBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/aStr" />

            <Button
                android:id="@+id/lBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/lStr" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/oBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/oStr" />

            <Button
                android:id="@+id/tBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/tStr" />

            <Button
                android:id="@+id/eBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/eStr" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1" >

            <Button
                android:id="@+id/dBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/dStr" />

            <Button
                android:id="@+id/hBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/hStr" />

            <Button
                android:id="@+id/aaBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight=".3"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/aStr" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

字符串.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="fStr">Fffffffff</string>
<string name="rStr">Rrrrrr</string>
<string name="sStr">Ssssss       </string>
<string name="lStr">Lllll</string>
<string name="oStr">Oooooooooooo</string>
<string name="tStr">Ttttt</string>
<string name="eStr">Eeeeee</string>
<string name="dStr">Dddddddddd</string>
<string name="cStr">Cccccccc</string>
<string name="hStr">Hhhh</string>
<string name="aStr">Aaaaaaaaaa aaaa</string>

</resources>

这个应用程序有问题。

  1. 按键图文差距太大,特别是5.1 WVGA屏幕。它在我的手机上看起来是一样的,它的屏幕尺寸是 4.​​5 英寸

以下是图片

在此处输入图像描述

我该如何解决这个问题?

4

3 回答 3

0

也许使用 LinearLayout ;

![<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeScreen" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="0.33"
            android:orientation="horizontal">

            <Button
                android:id="@+id/fBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/fStr" />

            <Button
                android:id="@+id/rBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/rStr" />

            <Button
                android:id="@+id/sBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/sStr" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="0.33"
            android:orientation="horizontal">

            <Button
                android:id="@+id/fBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/fStr" />

            <Button
                android:id="@+id/rBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/rStr" />

            <Button
                android:id="@+id/sBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/sStr" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="0.33"
            android:orientation="horizontal">

            <Button
                android:id="@+id/fBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/fStr" />

            <Button
                android:id="@+id/rBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/rStr" />

            <Button
                android:id="@+id/sBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/sStr" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="0.33"
            android:orientation="horizontal">

            <Button
                android:id="@+id/fBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/fStr" />

            <Button
                android:id="@+id/rBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/rStr" />

            <Button
                android:id="@+id/sBtn"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:drawableTop="@drawable/ic_launcher"
                android:layout_weight="0.33"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="@string/sStr" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

在此处输入图像描述

于 2013-10-22T08:15:12.610 回答
0

尝试使用 android:drawablePadding 和 android:paddingLeft 和 android:paddingRight

参考android:drawableLeft 边距和/或填充

于 2013-10-22T08:18:59.083 回答
0

这是一个修改后的版本,它将减小按钮的大小,并将它们放在它们的行内,并摆脱无用的 RelativeLayout 父级(正如 Lint 可能向你指出的那样):

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:stretchColumns="*"
    android:weightSum="4"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeScreen">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/fBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/rBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/sBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/cBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/aBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/lBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/oBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/tBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/eBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/dBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/hBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_gravity="center_vertical"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />

        <Button
            android:id="@+id/aaBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_launcher"
            android:layout_weight=".3"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="bla" />
    </TableRow>
</TableLayout>
于 2013-10-22T08:19:18.857 回答