A simple example of using Android’s Scrollview (with demo)

Time:2021-6-14

1. Vertical scroll: Scroll

Create a new application:

Do an experiment on the layout file of mainactivity. Now, after setting buttons 1 and 2, there are still some spaces left

image

Set another button 3 to get him out of the screen:

image

Now to run the program, you can’t slide or see the button 3.

image

How to set it?

1. Change the root layout of this layout file: change the root layout to: Scrollview

Note: there can only be one child element of Scrollview, so you need to add a LinearLayout layout and put other keys in the LinearLayout. Then there will be only one LinearLayout for the child elements of Scrollview, and there is no limit to the child elements of LinearLayout.

The code is as follows:

Run the program, and now you can scroll down to see button 3

image

2. Horizontal Scrollview

Create a new horizontalscrollview in LinearLayout. Similarly, only one child element can be created

image

Therefore, add a sub layout, LinearLayout, in the horizontal Scrollview layout, and the LinearLayout is horizontal

image

The code is as follows:

To run the application, because a layer of Scrollview is nested outside, you can scroll vertically and horizontally

image

Recommended Today

[database] MySQL exercises and answers (educational administration management system)_ MySQL_ 5.7)

✨ statement The answer to the exercise is not guaranteed to be completely correct, which is for reference only MySQL:5.7 Recommended software: Navicat premium Learning SQL statements requires diligent practice! ✨ Field description of each table course CId Course serial number, primary key PCId Prerequisite course DId Opening department number, foreign key CName Course name […]