安卓网格布局.GridLayout 单元格之间的边距 [英] Android GridLayout. Margins between GridLayout cells

查看:36
本文介绍了安卓网格布局.GridLayout 单元格之间的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在 ConstraintLayout 中的 GridLayout xml 代码

This is my GridLayout xml code that is inside ConstraintLayout

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context="solutions.elegant.com.procenty.activites.RabatActivity">

 <android.support.v7.widget.GridLayout
     android:layout_height="0dp"
     android:layout_width="0dp"
     android:layout_weight="4"
     app:rowCount="3"
     app:columnCount="4"
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintTop_toBottomOf="@id/btn_splaty"
     app:layout_constraintLeft_toLeftOf="parent"
     app:layout_constraintRight_toRightOf="parent"
     android:layout_marginLeft="50dp"
     android:layout_marginRight="50dp"
     android:layout_marginBottom="5dp"
     android:layout_marginTop="5dp"
     app:useDefaultMargins="false"
     app:orientation="horizontal">

     <Button
         style="@style/MyKeyboardButtons"
         android:id="@+id/btn_0"
         android:text="0" />
     <Button
         style="@style/MyKeyboardButtons"
         android:id="@+id/btn_1"
         android:text="1"
         />
     <Button
         style="@style/MyKeyboardButtons"
         android:id="@+id/btn_2"
         android:text="2" />
     <Button
         style="@style/MyKeyboardButtons"
         android:id="@+id/btn_3"
         android:text="3" />
     <Button
         style="@style/MyKeyboardButtons"
         android:id="@+id/btn_4"
         android:text="4" />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_5"
        android:text="5" />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_6"
        android:text="6" />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_7"
        android:text="7" />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_8"
        android:text="8" />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_9"
        android:text="9" />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_kropka"
        android:text="." />
     <Button
        style="@style/MyKeyboardButtons"
        android:id="@+id/btn_remove"
        android:text="l" />
 </android.support.v7.widget.GridLayout>
</android.support.constraint.ConstraintLayout>

这是按钮样式的代码:

<style name="MyKeyboardButtons">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">0dp</item>
    <item name="android:textSize">25sp</item>
    <item name="android:textColor">#ffffff</item>
    <item name="android:background">#151515</item>
    <item name="layout_columnWeight">1</item>
    <item name="layout_rowWeight">1</item>
    <item name="android:onClick">modifyET</item>
</style>

这是可见的结果:

现在我不喜欢按钮之间没有空格的事实,所以首先我添加到按钮样式行:

Now i don't like the fact that there is no space between the buttons so first I add to the button style line:

 <item name="android:layout_marginRight">2dp</item>

结果是:

我在 gridLayout 列之间添加了边距.现在我想在行之间添加边距,所以我再次向按钮样式添加一行:

I added a margin between gridLayout columns.Now I want to add margin between rows so I again add a line to the button style:

<item name="android:layout_marginBottom">2dp</item>

结果不是我所期望的:

问题是这里出了什么问题?我该如何解决这个问题,以便我在两者中都有利润按钮之间的尺寸?

The question is what is wrong here? How can I fix this so I have margins in both dimensions between the buttons?

推荐答案

仅尝试使用

<item name="android:layout_margin">1dp</item>

这篇关于安卓网格布局.GridLayout 单元格之间的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆