Gridlayout错误的单元格宽度大小

时间:2016-09-10 09:12:33

标签: android android-layout android-gridlayout

我在支持库中遇到Gridlayout的问题。我想让列相等,并且我使用grid:layout_columnWeigh进行此操作,但由于某些原因,列看起来并不相同:

enter image description here

activity_maps.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:grid="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:orientation="vertical">

    <android.support.v7.widget.GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="3"
        grid:alignmentMode="alignMargins"
        grid:columnCount="4"
        grid:columnOrderPreserved="false"
        grid:orientation="horizontal"
        grid:rowOrderPreserved="false"
        grid:useDefaultMargins="false">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_lat1"
            grid:layout_columnWeight="11"
            android:layout_width="63dp">

            <EditText
                android:id="@+id/lat1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="lat 1"
                android:inputType="numberDecimal|numberSigned" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_long1"
            grid:layout_columnWeight="1">

            <EditText
                android:id="@+id/long1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="long 1"
                android:inputType="numberDecimal|numberSigned" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_lat2"
            grid:layout_columnWeight="1">

            <EditText
                android:id="@+id/lat2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="lat 2"
                android:inputType="numberDecimal|numberSigned" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_long2"
            grid:layout_columnWeight="1"
            >

            <EditText
                android:id="@+id/long2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="long 2"
                android:inputType="numberDecimal|numberSigned" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_lat3"
            grid:layout_columnWeight="1">

            <EditText
                android:id="@+id/lat3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="lat 3"
                android:inputType="numberDecimal|numberSigned"
                grid:layout_columnWeight="1" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_long3"
            grid:layout_columnWeight="1">

            <EditText
                android:id="@+id/long3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="long 3"
                android:inputType="numberDecimal|numberSigned"
                grid:layout_columnWeight="1" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_lat4"
            grid:layout_columnWeight="1">

            <EditText
                android:id="@+id/lat4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="lat 4"
                android:inputType="numberDecimal|numberSigned" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_long4"
            grid:layout_columnWeight="1"
            android:layout_width="wrap_content">

            <EditText
                android:id="@+id/long4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="long 4"
                android:inputType="numberDecimal|numberSigned" />
        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/build_polygon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Build Polygon"
            grid:layout_columnSpan="2" />
    </android.support.v7.widget.GridLayout>

    <fragment xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        tools:context="com.geobox.MapsActivity" />
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

尝试在所有子组件中添加以下行

grid:layout_columnWeight="1"