Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.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 在android应用程序上删除第四列的表格布局_Java_Android_Android Layout - Fatal编程技术网

Java 在android应用程序上删除第四列的表格布局

Java 在android应用程序上删除第四列的表格布局,java,android,android-layout,Java,Android,Android Layout,我试图为android创建一个简单的计算应用程序。我使用了表格布局,添加了4行4列。我在每一列中添加一个按钮。我的问题是如下图所示的第4列被删掉, 下面是我的代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com

我试图为android创建一个简单的计算应用程序。我使用了表格布局,添加了4行4列。我在每一列中添加一个按钮。我的问题是如下图所示的第4列被删掉,

下面是我的代码

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.tashtoons.calculator.Calculator">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:weightSum="1"
        android:layout_alignParentRight="false"
        android:layout_alignParentEnd="false">

        <TextView
            android:layout_width="343dp"
            android:layout_height="77dp"
            android:id="@+id/answerScreen"
            android:layout_gravity="center_horizontal" />

        <TableLayout
            android:layout_width="371dp"
            android:shrinkColumns="1"
            android:layout_height="match_parent"
            android:baselineAligned="true">


            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:text="1"
                    android:id="@+id/button"

                    android:layout_column="0"

                    android:width="5px" />

                <Button


                    android:text="2"
                    android:id="@+id/button2"
                    android:layout_column="1"
                    android:width="5px" />

                <Button


                    android:text="3"
                    android:id="@+id/button3"
                    android:layout_column="2"
                    android:width="5px" />

                <Button


                    android:text="+"
                    android:id="@+id/button4"
                    android:layout_column="3"
                    android:width="5px" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button

                    android:text="4"
                    android:id="@+id/button5"
                    android:layout_column="0"

                    android:width="5px" />

                <Button


                    android:text="4"
                    android:id="@+id/button6"
                    android:layout_column="1"
                    android:width="5px" />

                <Button


                    android:text="5"
                    android:id="@+id/button7"
                    android:layout_column="2"
                    android:width="5px" />

                <Button


                    android:text="-"
                    android:id="@+id/button8"
                    android:layout_column="3"
                    android:width="5px" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button

                    android:text="6"
                    android:id="@+id/button9"
                    android:layout_column="0"

                    android:width="5px" />

                <Button


                    android:text="7"
                    android:id="@+id/button10"
                    android:layout_column="1"
                    android:width="5px" />

                <Button


                    android:text="8"
                    android:id="@+id/button11"
                    android:layout_column="2"
                    android:width="5px" />

                <Button


                    android:text="X"
                    android:id="@+id/button12"
                    android:layout_column="3"
                    android:width="5px" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button

                    android:text="9"
                    android:id="@+id/button13"
                    android:layout_column="0"

                    android:width="5px" />

                <Button


                    android:text="0"
                    android:id="@+id/button14"
                    android:layout_column="1"
                    android:width="5px" />

                <Button


                    android:text="%"
                    android:id="@+id/button15"
                    android:layout_column="2"
                    android:width="5px" />

                <Button


                    android:text="/"
                    android:id="@+id/button16"
                    android:layout_column="3"
                    android:width="5px" />
            </TableRow>
        </TableLayout>

    </LinearLayout>
</RelativeLayout>


我怎样才能阻止它停止呢?

试试这个,它可能会对你有所帮助

使用

android:layout\u width=“match\u parent”

在您的
表格布局中

而不是


android:layout\u width=“371dp”

使用下面的代码代替您的代码

当您必须为所有
按钮
文本视图
等提供
相同宽度时。
有
LinearLayout
的属性是
WeightSum
。这可以分为两部分

因此,将xml代码更改为以下格式

xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.softeng.xxy.ThirdActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:id="@+id/firstRow">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4">

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="1" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="2" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="3" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="+" />

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/secondRow"
        android:layout_below="@+id/firstRow">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4">

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="4" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="4" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="5" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="-" />

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/thirdRow"
        android:layout_below="@+id/secondRow">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4">

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="6" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="7" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="8" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="X" />

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/forthRow"
        android:layout_below="@+id/thirdRow">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4">

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="9" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="0" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="%" />

            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="/" />

        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>

输出:


如果视图的权重为1,则应将布局宽度设置为0dp,以使其在屏幕上具有均匀的大小或空间