【问题标题】:Android vertical space betwen buttonsAndroid 按钮之间的垂直空间
【发布时间】:2018-10-24 07:51:44
【问题描述】:

我对 Android 的布局有疑问。由于我使用的是瘦客户端提供商 Tabris,因此无法向您显示布局 xml 文件。下图显示了使用布局检查器记录的布局。我不明白为什么不同按钮之间有如此巨大的垂直空间。

Result Layout Inspector

当然我添加了布局检查器的布局属性(使用框架布局):

Layout Properties

也许你们中的一些人知道如何减少按钮之间的垂直空间。

【问题讨论】:

  • 你可以使用View
  • 请上传layout.xml
  • 如上所述,没有layout.xml,因为布局是在服务器端呈现的。
  • 当您像这样寻求帮助时,请始终在您的问题中添加相关代码,而不是一些部分屏幕截图,因为我们甚至无法从图像中复制粘贴。 编辑:由于布局是在服务器端呈现的,因此您会使用某种逻辑来呈现它,请考虑将这些逻辑添加到问题中

标签: android tabris


【解决方案1】:

我建议你使用 LinearLayouts

举例

 <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:layout_gravity="center"
   android:gravity="top|center">
        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/smsVerTit"
            android:textColor="@color/black"
            android:textSize="@dimen/BiggerTextSize"
            android:textStyle="bold"
            android:padding="10dp"/>

        <EditText
            android:id="@+id/smsCode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="7"
            android:gravity="center"
            android:hint="@string/smsCode"
            android:inputType="number"
            android:layout_marginTop="15dp"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="25dp"
            android:paddingBottom="10dp">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
               >
                <Button
                    android:id="@+id/cancelSMS"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/roundedbtn"
                    android:text="@string/cancel"
                    android:textColor="@android:color/white" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                >
                <Button
                    android:id="@+id/confirmSMS"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/roundedbtn"
                    android:text="@string/confirm"
                    android:textColor="@android:color/white" />
            </LinearLayout>
        </LinearLayout>
        <Button
            android:id="@+id/otherMethodSMS"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="?android:attr/selectableItemBackground"
            android:padding="10dp"
            android:text="@string/otherMethods"
            android:textColor="@color/colorPrimaryDark"
            android:layout_marginBottom="13dp"/>
      </LinearLayout>

【讨论】: