0

I am implementing an android application and I want to display something like the following picture, with an imageview and textview inside each square of the gridview but I am not able to have all the items fitting the whole screen. I have a limited nummber of items to show and I just want to put them fitting all the screen for any screen size without calculating dimensions and this. Can you help me?? Thanks.

introducir la descripción de la imagen aquí

main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rafad.betasentit.MainActivity">

<GridView
    android:id="@+id/appsGridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    android:numColumns="2">
</GridView>
</FrameLayout>

item.xml:

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="10dp">

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_weight="1"
    android:padding="5dp"
    android:background="@color/colorPrimary"/>
<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

alGhul7
  • 57
  • 1
  • 10
  • "I don't want it scrollable" - Then don't use a `GridView`. Use some other static `ViewGroup`; e.g., `GridLayout`, `TableLayout`, etc. – Mike M. Jan 21 '18 at 11:30
  • @MikeM. but GridLayout just allows to set single elements as its items, right? I cannot put load the file item.xml as an item of the layout as I do with gridview,, isn't it? – alGhul7 Jan 23 '18 at 11:18
  • Nah, you can nest `View`s in `GridLayout` just like you would in any other `ViewGroup`. Example: https://stackoverflow.com/a/10033481. – Mike M. Jan 23 '18 at 11:24

0 Answers0