在support.v7.widget.GridLayout中对齐child

时间:2016-06-21 08:10:42

标签: android

我有GridLayout

            <android.support.v7.widget.GridLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:layout_marginTop="10dp"
                app:alignmentMode="alignMargins"
                app:columnCount="2"
                app:rowOrderPreserved="true"
                app:useDefaultMargins="true">

                <com.app.views.deals.DealsTabletButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:d_icon="@drawable/deals_icon_red"
                    app:d_lower_text="@string/all_deals_right_active_now"
                    app:d_text="@string/deals"
                    app:d_upper_text="@string/view" />

                <com.app.views.deals.DealsTabletButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    app:d_icon="@drawable/categories_icon_red"
                    app:d_lower_text="@string/over_500_top_categories"
                    app:d_text="@string/category"
                    app:d_upper_text="@string/shop_by" />

                <com.app.views.deals.DealsTabletButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    app:d_icon="@drawable/brands_icon_red"
                    app:d_lower_text="@string/over_2500_popular_brands"
                    app:d_text="@string/brand"
                    app:d_upper_text="@string/shop_by" />

                <com.app.views.deals.DealsTabletButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginTop="2dp"
                    app:d_is_empty="true" />

            </android.support.v7.widget.GridLayout>

我想让这些孩子在GridLayout内对齐。目前,第二行有不同的差距。

如何正确对齐?

enter image description here

DealsTabletButton:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    android:background="@drawable/border_gray_solid_white"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingLeft="30dp"
    android:paddingRight="30dp"
    android:paddingTop="10dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <com.app.views.SvgImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginTop="15dp"
            android:id="@+id/icon"
            app:b_icon="@drawable/deals_icon_red" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="View"
                android:id="@+id/upperText"
                android:textColor="@color/black"
                android:textSize="15sp" />

            <TextView
                android:id="@id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="DEALS"
                android:textColor="@color/black"
                android:textSize="30sp" />

            <TextView
                android:id="@+id/lowerText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="All Deals Active Right Now!"
                android:textColor="@color/heading_gray"
                android:textSize="15sp" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

预期结果: enter image description here

我应该使用layout_weight标签吗?或GridLayout中有特殊标记?

0 个答案:

没有答案