I want to make a list with buttons using flexbox layout. If I use recyclerview and button with icon, the text does not fit in the button.
My recyclerview layout:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/category_button"
style="@style/Widget.Material3.Button.ElevatedButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:backgroundTint="@color/category_item_color"
android:checkable="true"
android:paddingStart="10dp"
android:paddingTop="5dp"
android:paddingEnd="10dp"
android:paddingBottom="5dp"
android:singleLine="true"
android:text="categoryText"
android:textColor="@color/white"
app:cornerRadius="14dp"
app:icon="@drawable/category_item_icon"
app:iconGravity="end"
app:iconTint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
My layout manager:
val layoutManager = FlexboxLayoutManager(this)
layoutManager.apply {
flexDirection = FlexDirection.ROW
flexWrap = FlexWrap.WRAP
}
I tried to remove the icon from the button, after that everything worked, but I would like the button with the icon. Also, If I remove the singleLine
param, the text in the button will move to the next line
Not the solution to your problem but an alternate way to use
cardView
as a parent and inside onetextView
and oneimageView
: