0

I am using Recyclerview with StaggeredGridLayoutManager

StaggeredGridLayoutManager gridLayoutManager =
            new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(gridLayoutManager);

I want variable columns having fixed height row.

item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <Button
        android:id="@+id/btnName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/button_bg"
        android:padding="4dp"
        android:singleLine="true"
        android:text="@string/category_name"
        android:textAppearance="@style/TextAppearance.AppCompat" />
</RelativeLayout>

Desired View Example

Desired view

Current view

Current view

Community
  • 1
  • 1
Sonam Pasi
  • 562
  • 1
  • 4
  • 19

2 Answers2

0

use this property

android:singleLine="true"

with buttons button this is not a solution to the large texts.

hope this will help you.

Nouman Ch
  • 4,023
  • 4
  • 29
  • 42
  • If I use **android:singleLine="true"** text will truncated. I don't want this. I want to adjust my layout like I have mentioned in the **desired view image** – Sonam Pasi Jan 25 '18 at 16:56
0

The behaviour that you want to achieve is not possible using StaggeredGridLayoutManager (according to my knowledge), because you must specify number of rows or columns that will have the same size.

The effect that you want to achieve could be possible with the ChipsLayoutManager library. I have used it with great success and can highly recommend it.

Kamil Dziadek
  • 196
  • 1
  • 5