Insert Scrollview into all Activity

Asked

Viewed 703 times

0

Hello, I need to insert a ScrollView throughout layout. But I’m not getting it. Follow my code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.gerdaumanagement.gerdaumanagement.MenuDrawer"
    tools:showIn="@layout/app_bar_menu_drawer"
    android:orientation="vertical">

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

        <Button
            android:id="@+id/button1"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button3"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

        <Button
            android:id="@+id/button4"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button5"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

        <Button
            android:id="@+id/button6"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

    </LinearLayout>

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

        <Button
            android:id="@+id/button"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

        <Button
            android:id="@+id/button8"
            android:layout_width="156dp"
            android:layout_height="156dp"
            android:text="Button" />

    </LinearLayout>

</LinearLayout>

1 answer

3


Fala Lucas,

Inside your Scrollview, you can only have one Layout, for example:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">

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

           <Button
               android:id="@+id/button1"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

           <Button
               android:id="@+id/button2"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

       </LinearLayout>
       <LinearLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content">

           <Button
               android:id="@+id/button3"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

           <Button
               android:id="@+id/button4"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

       </LinearLayout>
       <LinearLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content">

           <Button
               android:id="@+id/button5"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

           <Button
               android:id="@+id/button6"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

       </LinearLayout>

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

           <Button
               android:id="@+id/button"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

           <Button
               android:id="@+id/button8"
               android:layout_width="156dp"
               android:layout_height="156dp"
               android:text="Button" />

       </LinearLayout>
   </LinearLayout>
</ScrollView>

See that within Scrollview, you have a Linearlayout, and within Linearlayout you have the rest of the components.

Scrollview can only have one child.

  • 1

    Thank you very much Leonardo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.