APUNTES ANDROID
  • Introducción
  • Apuntes Linux
  • Apuntes Red Team
  • Apuntes Blue Team
  • Apuntes Python
  • Ricardev github
  • Escribiendo tu primera App
    • Instalar Android Studio
    • Proyecto
    • Ejecutar una App
    • Anatomía del Proyecto
      • Gradle scripts
      • AndroidManifest.xml
      • Java
      • Res
    • Componentes de una App
      • Activities
      • Fragments
      • Views y ViewGroups
      • Services
      • Broadcast Receivers
      • Intents
      • Content Provider
      • Widgets
    • Paradigmas de diseño
      • Views
        • Pallete Texts
          • TextView
          • EditText
          • AutoCompleteTextView
        • Pallete Buttons
          • Button
          • ImageButton
          • Chip y ChipGroup
          • RadioButton y RadioGroup
          • CheckBox
          • ToggleButton
          • Switch
          • FloatingActionButton
        • Pallete Widgets
          • ImageView
          • ShapeableImageView
          • WebView
          • VideoView
          • CalendarView
          • ProgressBar
          • SeekBar
          • RatingBar
          • SearchView
          • Divider
        • Custom Views
        • View Binding
      • Jetpack Compose
    • Layouts
      • FrameLayout
      • Linear Layout
      • Relative Layout
      • Constraint Layout
      • Table Layout
      • Grid Layout
    • Containers
      • Spinner
      • RecyclerView
      • CardView
      • ScrollView y HorizontalScrollView
      • ViewPager2
      • AppBarLayout y BottomAppBar
      • NavigationView y BottomNavigationView
      • Toolbar y MaterialToolbar
      • TabLayout y TabItem
      • ViewStub
      • etiquetas <include> y <merge>
Powered by GitBook
On this page
  • DEFINICIÓN
  • ScrollView
  • HorizontalScrollView
  • NestedScrollView
  • EJEMPLO
  • ScrollView
  • HorizontalScrollView
  1. Escribiendo tu primera App
  2. Containers

ScrollView y HorizontalScrollView

Explicación de los conceptos de ScrollView y HorizontalScrollView

PreviousCardViewNextViewPager2

Last updated 2 years ago

DEFINICIÓN

ScrollView

Hereda de FrameLayout.

Es un ViewGroup que permite que el Layout que se encuentra en su interior pueda ser scroleable.

Es recomendable que ScrollView tenga solo un hijo dentro debido a que es un FrameLayout.

Si es necesario introducir más de una View en su interior, entonces tendrá que añadir un ViewGroup en su interior para que se cumpla que solo tiene un único hijo directo.

Solo soporta scroll vertical.

HorizontalScrollView

Hereda de FrameLayout.

Es un ViewGroup que permite que el Layout que se encuentra en su interior pueda ser scroleable.

Es recomendable que ScrollView tenga solo un hijo dentro debido a que es un FrameLayout.

Si es necesario introducir más de una View en su interior, entonces tendrá que añadir un ViewGroup en su interior para que se cumpla que solo tiene un único hijo directo.

Solo soporta scroll horizontal.

NestedScrollView

Hereda de FrameLayout.

Es un ScrollView más moderno que puede funcionar tanto de padre como de hijo de otro ViewGroup.

Solo soporta scroll vertical.

RECOMENDACIÓN

Es recomendable utilizar NestedScrollView siempre que se necesite un Scroll Vertical ya que es más configurable por el usuario y soporta las necesidades de Material Design en cuanto a Scrolling.

EJEMPLO

Ya se han utilizado ScrollViews en diferentes ejemplos de esta guía así que vamos a coger uno para verlo:

ScrollView

<?xml version="1.0" encoding="utf-8"?>
<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"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/im_pyramidhead" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/shapeable_image"/>

    </LinearLayout>


</ScrollView>

HorizontalScrollView

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView 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"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/im_pyramidhead" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/shapeable_image"/>

    </LinearLayout>


</HorizontalScrollView>
ScrollView  |  Android DevelopersAndroid Developers
Fuente: developer.android
HorizontalScrollView  |  Android DevelopersAndroid Developers
Fuente: developer.android
NestedScrollView  |  Android DevelopersAndroid Developers
Fuente: developer.android
ScrollView
HorizontalScrollView
Logo
Logo
Logo