-3

I have a layout like this

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="16dp"
    android:isScrollContainer="true">

    <Button
        android:layout_width="180dp"
        android:layout_height="300dp"
        android:text="Button1"
        android:layout_gravity="left"
        android:layout_row="0"
        android:layout_column="0"></Button>

    <Button
        android:layout_width="180dp"
        android:layout_height="300dp"
        android:text="Button2"
        android:layout_gravity="right"
        android:layout_row="0"
        android:layout_column="1"></Button>

    <Button
        android:layout_width="180dp"
        android:layout_height="300dp"
        android:text="Button3"
        android:layout_gravity="left"
        android:layout_row="1"
        android:layout_column="0"></Button>

    <Button
        android:layout_width="180dp"
        android:layout_height="300dp"
        android:text="Button4"
        android:layout_gravity="right"
        android:layout_row="1"
        android:layout_column="1"></Button>

    <Button
        android:layout_width="180dp"
        android:layout_height="300dp"
        android:text="Button5"
        android:layout_gravity="left"
        android:layout_row="2"
        android:layout_column="0"></Button>

    <Button
        android:layout_width="180dp"
        android:layout_height="300dp"
        android:text="Button6"
        android:layout_gravity="right"
        android:layout_row="2"
        android:layout_column="1"></Button>
    
</GridLayout>

Normally I will fit everything into a Relative or Constraint layout. But this time I intentionally made it big so that Button5 and Button6 can't be seen. And what I want is to make the layout scrollable so that the user can scroll up to see the Button5 and Button6?

How can I do it? What layout is to be used? Is there a way to make other layouts scrollale?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Phat Tran
  • 65
  • 3
  • 1
    `scrollview` is this what you want ? – aryanknp Sep 15 '20 at 04:10
  • Does this answer your question? [How do you make a LinearLayout scrollable?](https://stackoverflow.com/questions/4055537/how-do-you-make-a-linearlayout-scrollable) – Ryan M Sep 16 '20 at 07:21

1 Answers1

1

You have to do this if you want to scroll your view

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:padding="16dp">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <GridLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:layout_width="180dp"
            android:layout_height="300dp"
            android:layout_row="0"
            android:layout_column="0"
            android:layout_gravity="left"
            android:text="Button1"></Button>

        <Button
            android:layout_width="180dp"
            android:layout_height="300dp"
            android:layout_row="0"
            android:layout_column="1"
            android:layout_gravity="right"
            android:text="Button2"></Button>

        <Button
            android:layout_width="180dp"
            android:layout_height="300dp"
            android:layout_row="1"
            android:layout_column="0"
            android:layout_gravity="left"
            android:text="Button3"></Button>

        <Button
            android:layout_width="180dp"
            android:layout_height="300dp"
            android:layout_row="1"
            android:layout_column="1"
            android:layout_gravity="right"
            android:text="Button4"></Button>

        <Button
            android:layout_width="180dp"
            android:layout_height="300dp"
            android:layout_row="2"
            android:layout_column="0"
            android:layout_gravity="left"
            android:text="Button5"></Button>

        <Button
            android:layout_width="180dp"
            android:layout_height="300dp"
            android:layout_row="2"
            android:layout_column="1"
            android:layout_gravity="right"
            android:text="Button6"></Button>
    </GridLayout>
</ScrollView>
</GridLayout>
Syed Rafaqat Hussain
  • 1,009
  • 1
  • 9
  • 33