I'm developing an app, the have 100 buttons. And I want to put all the buttons inside the screen. I'm using a GridLayout with all the buttons inside the problem that I am having is that the buttons are getting out of the screen.
This is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/app_bar_main"
android:layout_column="1">
<GridLayout
android:id="@+id/GridLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="6"
android:rowCount="17"
android:orientation="vertical">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/numero_1"
android:id="@+id/button1"/>
The question that I have is: Is this possible to do? And this is the best approach?
I made other test where I changed the size of the image. The result is not what i expected header
Result with a different size image
As you can see in the second image the buttons in the rows are inside the screen but the position of the buttons is not ok, there are a lot of space between the last button of the row and the end of the screen.
The solution that I am looking for, is to have a layout that don't allow the buttons to get out of the screen, and that resizes the space between the buttons and the edges automatically, if the screen size is different the layout will automatically adapt to the size of the screen.