android - 网格布局的对齐问题

标签 android

我有一个如图所示的数字键盘

here

如您所见,只有单行的按钮没有正确对齐。我知道通过将 android:baselineAligned 设置为 false 我们可以解决这个问题。但是 GridLayout 没有任何这样的属性。

我该如何解决?

编辑:

<RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" >

        <GridLayout
            android:id="@+id/buttons_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alignmentMode="alignMargins"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/phone_number"
            android:layout_marginRight="@dimen/buttons_margin_right"
            android:layout_marginTop="10dp"
            android:columnCount="3" >

            <Button
                android:id="@+id/button1"
                android:layout_width=""65dp
                android:layout_height=""40dp
                android:textColor="@android:color/white"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:layout_marginLeft="10dp"
                android:text="1" />

           <Button
                android:id="@+id/button2"
                android:layout_width=""65dp
                android:layout_height=""40dp
                android:textColor="@android:color/white"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:layout_marginLeft="10dp"
                android:text="2\nABC" />

.
.
.
      </GridLayout>
<RelativeLayout>

最佳答案

我也遇到了同样的问题,即 textview 的固定高度是 appcombat GridLayout 的子项。 每次我有一个带有两行 TextView 的单元格而不像其他单元格只有一行时,就会出现错误的对齐方式。

对我来说,当我添加

时,行已正确对齐

grid:layout_rowWeight="1"

无法解释,但确实有效。

关于android - 网格布局的对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14831507/

相关文章:

android - 从 SQL 数据库中提取单行

java - Android 照片应用程序错误

android - 淡入淡出动画闪烁 - Android

android - 获取 "java.lang.IllegalArgumentException: Unknown URL content in"Android

android - 如何在android中获取用相机拍摄的最后一张照片?

java - 将字节数组转换为具有同等字节数的字符串

Android 将事件添加到 CustomPreference 元素 (TextView)

android - 如何预览 xml drawable?

java - 除非通过第二个 Java Activity 向后提示,否则我的第一个 Java Activity 中的动画不起作用

android - 我的应用程序只是构建并且从未在实际设备上安装 apk(Android Studio)