0

Olá, preciso inserir uma ScrollView em todo layout. Mas não estou conseguindo. Segue o meu código.

<?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 Resposta 1

3

Fala Lucas,

Dentro do seu ScrollView, você só pode ter um Layout, por exemplo:

<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>

Veja que dentro do ScrollView, tem um LinearLayout, e dentro do LinearLayout tem o restante dos componentes.

O ScrollView só pode ter um filho.

1
  • 1
    Muito obrigado Leonardo Commented 16/05/2017 às 17:02

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .