0

hi I create an activity with relative layout/scrollview/gridlelayout but my application didnt open. what is my mistake? is not gridlelayout use within scrollview? hi I create an activity with relative layout/scrollview/gridlelayout but my application didnt open. what is my mistake? is not gridlelayout use within scrollview?

thanks alot.

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.peg.MainActivity">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:columnCount="1"
            android:rowCount="1">

            <Button
                android:id="@+id/s"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_margin="20dp"
                android:layout_row="0"
                android:background="@drawable/s" />

            <Button
                android:id="@+id/hur"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_margin="20dp"
                android:layout_row="1"
                android:background="@drawable/hur" />

            <Button
                android:id="@+id/mil"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_margin="20dp"
                android:layout_row="0"
                android:background="@drawable/mil" />

            <Button
                android:id="@+id/ysr"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_margin="20dp"
                android:layout_row="1"
                android:background="@drawable/ysr" />
        </GridLayout>
    </ScrollView>
</RelativeLayout>
a.alld
  • 3
  • 5

2 Answers2

0

I think your problem is in items count You have 4 buttons but only one row and only one cell, try with:

   <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="2"
        android:rowCount="2">

I would advice you to use RecyclerView if your view get more complicated.

MeLean
  • 3,092
  • 6
  • 29
  • 43
0

Try this

you increase the android:columnCount="2" and android:rowCount="2" in Gridlayout

<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:columnCount="2"
            android:orientation="horizontal"
            android:rowCount="2">

            <Button
                android:id="@+id/s"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_margin="20dp"
                android:layout_row="0"
                android:background="@mipmap/ic_launcher" />

            <Button
                android:id="@+id/hur"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_margin="20dp"
                android:layout_row="1"
                android:background="@mipmap/ic_launcher" />

             <Button
                android:id="@+id/mil"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_margin="20dp"
                android:layout_row="0"
                android:background="@mipmap/ic_launcher" />

            <Button
                android:id="@+id/ysr"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_margin="20dp"
                android:layout_row="1"
                android:background="@mipmap/ic_launcher" />
        </GridLayout>
    </ScrollView>
</RelativeLayout>

OUTPUT

enter image description here

Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31