i want to display in a fragment 1 button, below this one gridView below which we have another button.
Everything is wrapped in a RelativeLayout like this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/gridview_bouton_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/creer_categorie"
android:layout_centerHorizontal="true"></Button>
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:horizontalSpacing="8dp"
android:numColumns="3"
android:verticalSpacing="8dp"
android:padding="10dp"
android:layout_below="@+id/gridview_bouton_new">
</GridView>
<Button
android:id="@+id/gridview_bouton_valider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/valider"
android:layout_below="@+id/gridView"
android:layout_centerHorizontal="true"></Button>
It works fine until i have many items in the gridView. Above 6 rows the fragment get vertically scrollable but the last button disappears !
I tried to nest everything in a ScrollView but only the first row is displayed....
If anyone has the solution it would be very helpful !!
Consider using RecyclerView for this purpose: https://developer.android.com/guide/topics/ui/layout/recyclerview
GridView is deprecated now and is not recommended to use. Also it is pretty limited.
RecyclerView, on the other hand, gives you ability to display as many items as you want dynamically.
You can also use GridLayoutManager to achieve desired grid look: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/GridLayoutManager