Insert ScrollView throughout Activity

0

Hello, I need to insert a ScrollView into the entire layout . But I can not. Here's 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>
    
asked by anonymous 16.05.2017 / 18:53

1 answer

3

Speak Luke,

Within 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 the ScrollView, you have a LinearLayout, and within the LinearLayout you have the rest of the components.

The ScrollView can only have one child.

    
16.05.2017 / 18:59