【问题标题】:Support v7 GridLayout doesn't stretch columns支持 v7 GridLayout 不拉伸列
【发布时间】:2015-11-20 16:19:31
【问题描述】:

我正在尝试在我的项目中使用支持库中的 GridLayout。我所做的只是将它作为 Android 库添加到我的项目中。我创建了一个简单的布局来显示什么不工作。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.example.myapp"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v7.widget.GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/margin"
    app:columnCount="3"
    app:rowCount="8"
    tools:context=".RegistrationActivity" >

    <Button
        android:id="@+id/activity_registration_company"
        app:layout_columnSpan="3"
        android:background="@android:color/darker_gray"
        android:text="1" />

    <Button
        android:id="@+id/activity_registration_street"
        app:layout_columnSpan="2"
        android:background="@android:color/darker_gray"
        android:text="2" />

    <Button
        android:id="@+id/activity_registration_building"
        app:layout_columnSpan="1"
        android:background="@android:color/darker_gray"
        android:text="3" />
</android.support.v7.widget.GridLayout>

这是我在 Eclipse 布局编辑器中看到的(在设备上相同):

如您所见,GridLayout 的内容并没有占据整个宽度。 Button 也不占用 span 定义的空间。有什么想法吗?

【问题讨论】:

    标签: android grid-layout android-support-library android-gridlayout


    【解决方案1】:

    使用 android:layout_columnWeight="X"(X 是你想要的任何数字)和android:layout:width="0dp"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      相关资源
      最近更新 更多