0

I have 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>

I would like to have this childs aligned inside GridLayout. For now there are different gaps in the second row.

How to align it properly?

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>

Expected result: enter image description here

Should I use layout_weight tag ? or there is special tag in GridLayout ?

VLeonovs
  • 2,193
  • 5
  • 24
  • 44
  • I can't notice the differences between your result and want you want to achieve – Luca Nicoletti Jun 21 '16 at 08:14
  • @LucaNicoletti the gray colored element "Shortcut" not aligned with "CATEGORY". The "BRAND" not aligned with "DEALS". I'm speaking about right side of these views. I would like to have 1:1:1:1 ratio of elements. But elements from the second row not aligned properly – VLeonovs Jun 21 '16 at 08:17
  • That's cause width & width in your second level `` of `DealsTabletButton` are setted to `"wrap_content"` so if the content is smaller, the tables are smaller. Try to set it to `"match_parent"` and let me know if it brokes everything or not :p – Luca Nicoletti Jun 21 '16 at 08:20
  • @LucaNicoletti unfortunately your approach is not working – VLeonovs Jun 21 '16 at 08:27
  • http://stackoverflow.com/questions/10016343/gridlayout-not-gridview-how-to-stretch-all-children-evenly have a look here – Luca Nicoletti Jun 21 '16 at 08:30

0 Answers0