Original: Android 0 Basics Section 61st: Scrolling view ScrollView
Previous installments studied ProgressBar series components, Viewanimator series components, Picker series components, and time-date series components, and then continued to learn about other common components.
I. Overview of ScrollView
From the previous study some students may have found that when there is a lot of content when the screen display is not complete, the part of the display is completely invisible. But in the actual project, a lot of content is more than one screen width or height, how to do? That will require the ScrollView of this section to be completed.
By default, ScrollView just adds a vertical scroll bar for other components, and if the app needs to add a horizontal scroll bar, it can be implemented with another scrolling view Horizontalscrollview. ScrollView is basically similar to the Horizontalscrollview function, except that the former adds a vertical scrollbar, which adds a horizontal scroll bar.
ScrollView is derived from framelayout, a component that is used to add a scrollbar to a normal component. ScrollView can contain a maximum of one component, and ScrollView's role is to add a vertical scroll bar for that component.
The XML attributes supported by ScrollView are as follows:
ANDROID:SCROLLX: Sets the offset value for horizontal scrolling in pixels.
Android:scrolly: Sets the offset value for vertical scrolling in pixels.
Android:scrollbaralwaysdrawhorizontaltrack: Sets whether the vertical scroll bar is always displayed.
Android:scrollbaralwaysdrawverticaltrack: Sets whether the vertical scroll bar is always displayed.
Android:scrollbardefaultdelaybeforefade: Sets the start of the fade, in milliseconds, after n milliseconds.
Android:scrollbarfadeduration: Sets the time, in milliseconds, for the scrollbar fade-out effect (from there to slowly fade to disappear).
Android:scrollbarsize: Sets the width of the scroll bar.
Android:scrollbarstyle: Sets the style and position of the scroll bar. There are several property values:
Outsideinset: The scrollbar is displayed at the edge of the view, adding the view's padding. If possible, the scrollbar only covers the background of the view.
Outsideoverlay: The scrollbar is displayed on the edge of the view, without adding the view's padding, the scrollbar will be covered with translucency.
Insideinset: The scrollbar appears in the padding area, adding the padding area of the control, which does not overlap the contents of the view.
Insideoverlay: The scrollbar is displayed inside the content area without adding the padding area of the control, which overrides the view content in a translucent style.
Android:scrollbarthumbhorizontal: Sets the drawable of the horizontal scroll bar.
Android:scrollbarthumbvertical: Sets the drawable of the vertical scroll bar.
Android:scrollbartrackhorizontal: Sets the color drawable of the horizontal scroll bar background (track).
Android:scrollbartrackvertical: Sets the drawable of the vertical scroll bar background (track).
Android:scrollbars: Sets the scroll bar display. Property values are: None, horizontal, vertical.
Several common methods of ScrollView are:
AddView (View child): Adds a sub-view. If the layout parameter is not set for the child view beforehand, the child view is set with the default parameters of the current viewgroup.
AddView (view child, int index): Adds a sub-view. If the layout parameter is not set for the child view beforehand, the child view is set with the default parameters of the current viewgroup.
Arrowscroll (int direction): Handles scrolling the scroll bar when the up and down arrows are clicked.
Fling (int velocityy): Slide (Fling) gesture of the scrolling view.
Ii. Examples of ScrollView
Next, a simple example program is used to learn the use of ScrollView.
Continue to use the Advancedviewsample module of the Widgetsample project to create a scrollview_layout.xml file in the app/main/res/layout/directory populated with the following code snippet:
<?XML version= "1.0" encoding= "Utf-8"?><ScrollViewxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:orientation= "vertical"android:padding= "10DP"Android:fillviewport= "false"> <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "vertical"> <ImageViewAndroid:id= "@+id/imageview"Android:layout_width= "Wrap_content"Android:layout_height= "200DP"Android:scaletype= "Centercrop"android:src= "@drawable/image" /> <ButtonAndroid:id= "@+id/more_btn"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "More" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "ScrollView"android:textappearance= "? Android:attr/textappearancelarge" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/description"android:textappearance= "? Android:attr/textappearancesmall" /> </LinearLayout></ScrollView>
Where description is a defined string, it is not given here because there is more content.
Run the program, you can see the interface effect shown, the interface can scroll up and down.
About ScrollView Learn here first, more usage suggest yourself to practice more.
Come here today, if you have any questions welcome message to discuss together, also welcome to join the Android 0 Basic introductory Technical discussion group, grow together!
This article copyright for the public Share talent show (Shareexpert)--Xin 鱻 all, if necessary reprint please contact the author authorized, hereby declare!
Past period Summary share:
Android 0 Basics Introduction 1th: Android's past life
Android 0 Basics Section 2nd: Android system Architecture and application components those things
Android 0 Basics Section 3rd: Bring you up to talk about Android development environment
Android 0 Basics 4th: Installing and configuring the JDK correctly Ko fu the first trick
Android 0 Basics 5th: Use ADT bundles to easily meet the goddess
Android 0 Basics 6th: Configuration Optimization SDK Manager, official dating goddess
Android 0 Basics 7th: Take care of Android simulator and start the Sweet journey
Android 0 Basics 8th: HelloWorld, the starting point for my first trip
Android 0 Basics 9th: Android app, no code can be developed
Android 0 Basics Section 10th: Development IDE Big upgrade, finally ushered in Android Studio
Android 0 Basics Introductory Section 11th: Simple steps to take you to fly, run Android Studio project
Android 0 Basics 12th: Get familiar with the Android studio interface and start selling
Android 0 Basics 13th: Android Studio Configuration optimization to create a development tool
Android 0 Basics 14th: Using high-speed genymotion, stepping into the rocket era
Android 0 Basics Section 15th: Mastering the Android Studio project structure, sailing
Android 0 Basics Section 16th: Android User Interface Development overview
Android 0 Basics Section 17th: text box TextView
Android 0 Basics Section 18th: Input box EditText
Android 0 Basics Get started section 19th: Buttons button
Android 0 Basics 20th: check box checkbox and radio button radiobutton
Android 0 Basics Section 21st: Switch Components ToggleButton and switch
Android 0 Basics Section 22nd: Image View ImageView
Android 0 Basics Section 23rd: Image button ImageButton and zoom button Zoombutton
Android 0 Basics Section 24th: Customize view simple to use to create your own controls
Android 0 Basics Section 25th: Simple and most commonly used linearlayout linear layouts
Android 0 Basics Section 26th: Two alignments, layout_gravity and gravity differ greatly
Android 0 Basics section 27th: Using padding and margin correctly
Android 0 Basics Section 28th: Easy to master relativelayout relative layout
Android 0 Basics 29th: Use tablelayout table layouts
Android 0 Basics 30th: Two minutes master Framelayout frame layout
Android 0 Basics Section 31st: absolutelayout absolute Layout with less
Android 0 Basics Section 32nd: New GridLayout Grid layout
Android 0 Basics section 33rd: Android Event Handling overview
Android 0 Basics Section 34th: Listening-based event handling in Android
Android 0 Basics Section 35th: Callback-based event handling in Android
Android 0 Basics Section 36th: Handling of Android system events
Android 0 Basics 37th: First Knowledge ListView
Android 0 Basics 38th: First Knowledge Adapter
Android 0 Basics section 39th: listactivity and custom list items
Android 0 Basics Section 40th: Customizing Arrayadapter
Android 0 Basics Section 41st: Using Simpleadapter
Android 0 Basics Section 42nd: Customizing Baseadapter
Android 0 Basics section 43rd: ListView Optimization and List End-to-end use
Android 0 Basics Section 44th: ListView Data Dynamic Update
Android 0 Basic Getting Started section 45th: Grid view GridView
Android 0 Basics section 46th: List Options Box spinner
Android 0 Basic Getting Started section 47th: AutoComplete text Box Autocompletetextview
Android 0 Basics Section 48th: Collapsible list Expandablelistview
Android 0 Basics section 49th: Adapterviewflipper picture Carousel
Android 0 Basics Section 50th: StackView card Stacking
Android 0 Basics Section 51st: progress bar ProgressBar
Android 0 Basics section 52nd: Customizing ProgressBar Cool progress bar
Android 0 Basics 53rd: Drag bar Seekbar and star rating bar Ratingbar
Android 0 Basics section 54th: View switch Components Viewswitcher
Android 0 Basics Section 55th: Imageswitcher and Textswitcher
Android 0 Basics Section 56th: Flip View Viewflipper
Android 0 Basics Section 57th: DatePicker and Timepicker selectors
Android 0 Basics Section 58th: Value selector numberpicker
Android 0 Basics Section 59th: Common Three clock clocks components
Android 0 Basics Section 60th: Calendar view CalendarView and timer chronometer
Android 0 Basics Section 61st: Scrolling view ScrollView