0

I am trying to make layout like this enter image description here

I am trying to use GridLayout to achieve this but the issue I am getting is some buttons are small in size and some are bigger in size. For the small size buttons it should move the next button closer to the last button but its not doing that. Its doing this enter image description here

Any Idea of how to achieve this with Grid Layout or any other layout. This is the code for grid layout I am using

    <GridLayout
        android:layout_width="match_parent"
        android:layout_marginTop="@dimen/_16ssp"
        android:columnCount="3"

        android:layout_marginHorizontal="@dimen/_16ssp"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="ALL"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="Default"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="Default"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:layout_marginTop="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="Default"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:layout_marginTop="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="Default"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:layout_marginTop="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="Default"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/_16ssp"
            android:layout_marginTop="@dimen/_16ssp"
            android:background="@drawable/grey_20dp_10op"
            android:paddingHorizontal="@dimen/_32ssp"
            android:paddingVertical="@dimen/_8ssp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/regular"
                android:text="Default"

                android:textColor="@color/black"
                android:textSize="@dimen/_12ssp"></TextView>
        </LinearLayout>




    </GridLayout>
  • Does this answer your question? [RecyclerView with StaggeredGridLayoutManager : variable number of columns and vertically scrollable](https://stackoverflow.com/questions/59998188/recyclerview-with-staggeredgridlayoutmanager-variable-number-of-columns-and-ve) – Andrew Dec 27 '22 at 17:38
  • You should look into this: https://stackoverflow.com/questions/34216890/android-difference-between-gridlayout-and-staggered-gridlayout – Samir Spahic Dec 28 '22 at 12:44

0 Answers0