I am trying to use a gridView for a game with different board sizes. I sets the number of columns programmatically for the GridView, each column got an fixed size button inside it.The GridView width is set to "wrap_content" in the xml. However - The gridView is always spread as "match_parent" to the entire screen. Here hows it look:
This is mine GridView xml (It in a constrain layout). I already tried to add weight or wrap it with linear layout. I added : android:gravity="center" and android:layout_centerInParent="true" In addition I tried changing the stretchMode but it just got the columns to be with a huge spacing between each other, or got them to be rectangle when I really want to keep them squre.
<GridView
android:id="@+id/gridView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="24dp"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="32dp"
android:layout_weight="0.5"
android:columnWidth="64dp"
android:gravity="center"
android:layout_centerInParent="true"
android:horizontalSpacing="2dp"
android:stretchMode="none"
android:verticalSpacing="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2"></GridView>
I couldn't find any working solution online, Hope you can help, Thanks !