Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 按钮大小不一样_Java_Android_Eclipse_Button_User Interface - Fatal编程技术网

Java 按钮大小不一样

Java 按钮大小不一样,java,android,eclipse,button,user-interface,Java,Android,Eclipse,Button,User Interface,我创建了一个具有“相同大小”按钮的应用程序,并向其中添加了同样大小的图像。下面是我的代码 <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_paren

我创建了一个具有“相同大小”按钮的应用程序,并向其中添加了同样大小的图像。下面是我的代码

<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/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" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

我如何解决这个问题

将所有
按钮
android:layout\u width
更改为
fill\u parent

android:layout_width="fill_parent"

将所有的
按钮
android:layout\u width
更改为
fill\u parent

android:layout_width="fill_parent"

尝试将
版面宽度设置为0dp,这对我以前解决了此问题。

尝试将
版面宽度设置为0dp,这对我以前解决了此问题。

尝试以下方法:


尝试以下方法:



更改表格行的“布局:宽度”属性(带有填充父行)

 android:layout_width="fill_parent"

更改具有填充父级的表格行的布局:宽度属性

 android:layout_width="fill_parent"

我同意并建议使用
layout\u weight
视图
对象之间进行分配或划分宽度

另外,在查看您的代码时,我建议使用较小的视图,因为您使用的是
TableLayout
,如果您仅使用带有三个按钮的
LinearLayout
,并且正确使用上述属性,则实际上不需要使用该视图

我也不确定在这种情况下为什么需要
RelativeLayout
。如果您使用android sdk中的hierarchy viewer工具,那么您将了解到使用布局的视图数量越少,屏幕将使用的内存越低,因此响应速度越快


后者只是一个建议

我同意并建议使用
layou weight
视图
对象之间进行分配或划分宽度

另外,在查看您的代码时,我建议使用较小的视图,因为您使用的是
TableLayout
,如果您仅使用带有三个按钮的
LinearLayout
,并且正确使用上述属性,则实际上不需要使用该视图

我也不确定在这种情况下为什么需要
RelativeLayout
。如果您使用android sdk中的hierarchy viewer工具,那么您将了解到使用布局的视图数量越少,屏幕将使用的内存越低,因此响应速度越快


后者只是一个建议

我想你可以解决这个问题

<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"

我想你可以解决这个问题

<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"

对于按钮,您使用的是权重属性和widt=“wrap\u content”。对于正在使用权重属性和widt=“wrap\u content”的按钮,尝试使用layout\u width=“0dip”而不是wrap\u content。尝试使用layout_width=“0dip”而不是wrap_contentyep,将其设置为
0dp
0dip
应使其使用权重。否则您将覆盖权重属性+1你的意思是“布局宽度”?谢谢你的回复。但是布局的宽度是什么?任何元素的宽度,你都有权重。是的,就是这个。谢谢你!是的,将其设置为
0dp
0dip
应使其使用权重。否则您将覆盖权重属性+1你的意思是“布局宽度”?谢谢你的回复。但是布局的宽度是什么?任何元素的宽度,你都有权重。是的,就是这个。谢谢你!