Android 删除行之间的间距
您好,我正在开发一个小型计算器应用程序,我想删除按钮行和列之间的间距。我想让计算器按钮相互连接。就像地砖一样,我使用网格布局,但任意两个按钮之间仍留有少量空间 这是布局xml文件:Android 删除行之间的间距,android,android-layout,Android,Android Layout,您好,我正在开发一个小型计算器应用程序,我想删除按钮行和列之间的间距。我想让计算器按钮相互连接。就像地砖一样,我使用网格布局,但任意两个按钮之间仍留有少量空间 这是布局xml文件: 看起来可能是因为您正在将按钮设置为特定的大小。为了简单起见,我将在水平方向上进行解释,但在垂直方向上基本上也发生了同样的事情。对于水平方向,指定80dp作为按钮宽度,但将gridlayout宽度设置为与父项匹配。如果您的按钮没有填充网格布局根据其总宽度分配给它们的总实际尺寸的宽度(在您定义的布局中,总宽度由屏幕宽
看起来可能是因为您正在将按钮设置为特定的大小。为了简单起见,我将在水平方向上进行解释,但在垂直方向上基本上也发生了同样的事情。对于水平方向,指定80dp作为按钮宽度,但将gridlayout宽度设置为与父项匹配。如果您的按钮没有填充网格布局根据其总宽度分配给它们的总实际尺寸的宽度(在您定义的布局中,总宽度由屏幕宽度决定),则按钮周围可能会有额外的空间。看起来您似乎为按钮尺寸指定了固定的宽度和高度。如果您使用特定的高度和宽度,它在不同的屏幕上看起来可能不同
您可以使用LinearLayout代替GridLayout,如下所示
我想这可能会对你有所帮助:)
将
android:clipToPadding=“false”
应用于父布局或将背景色应用于按钮。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/calc_board"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:inputType="text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/clear_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
<Button
android:id="@+id/clear_bt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
<Button
android:id="@+id/clear_bn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
<Button
android:id="@+id/clea"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/clea1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
<Button
android:id="@+id/clea2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
<Button
android:id="@+id/clea3r_bn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
<Button
android:id="@+id/clea4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Clear"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>