Objective
This blog mainly explains the use of ScrollView and Horizontalscrollview two containers. They represent both vertical scrolling and horizontal scrolling, and the scrolling content is the view it contains. In this article we will briefly describe the use of ScrollView and Horizontalscrollview, as well as considerations, and finally a simple demo to illustrate the use of these two containers.
ScrollView
ScrollView, through the inheritance of official documents, can be seen that it inherits from Framelayout, so it is a special type of framelayout because it can use the user scroll to display a list of views that occupy more space than the physical display. It is important to note that ScrollView can only contain one child view or view group, and in the actual project, it usually contains a vertical linearlayout.
It is important to note that ScrollView cannot be used with the ListView because the ListView has already handled the vertical scrolling, forcing the vertical scrolling effect if the contents of the ListView are larger than the contents of the physical view. So there is no point in using ScrollView and ListView mixing, for the ListView, see my other blog: Android--ui's listview. ScrollView also need to pay attention to the edittext of the multi-line input of the scrolling effect, but also can not be mixed, if the ScrollView contains multiple lines of EditText, the edittext of the own scrolling effect will be invalidated. The central idea is that ScrollView is a container for scrolling views, and it is not possible to mix it with some controls that have their own scrolling effect.
Under the Android platform, there is a Horizontalscrollview container similar to ScrollView, which has the opposite effect on ScrollView, which is mainly applied to horizontal scrolling, Understand ScrollView basically understand the Horizontalscrollview, so here focus on the use of ScrollView.
Sample Demo
ScrollView is actually a layout, so there is basically not much of your own methods or attributes that need to be specifically explained. Here is a demo to illustrate the use and effects, here are 10 images, which need to be placed in the RES/DRAWABLE-HDPI directory.
Layout code:
1 <?xml version= "1.0" encoding= "Utf-8"?> 2 <scrollview xmlns:android= "http://schemas.android.com/apk/res/ Android "3 android:layout_width=" match_parent "4 android:layout_height=" Match_parent "> 5 6 <linearlayo UT 7 android:layout_width= "match_parent" 8 android:layout_height= "wrap_content" 9 Android:orientat ion= "vertical" >10 <textview12 android:layout_width= "Match_parent" Android:layo ut_height= "wrap_content" android:text= "vertical scrolling View" android:textsize= "30DP"/>16 < IMAGEVIEW18 android:layout_width= "match_parent" android:layout_height= "Wrap_content" 20 android:src= "@drawable/bmp1"/>21 <imageview23 android:layout_width= "Match_parent" 24 android:layout_height= "Wrap_content" android:src= "@drawable/bmp2"/>26 <imageview28 Android:layout_widtH= "Match_parent" android:layout_height= "wrap_content" "android:src=" @drawable/bmp3 "/>31 32 <edittext33 android:maxlines= "2" android:layout_width= "Match_parent" droid:layout_height= "40DP"/>36 PNs <imageview38 android:layout_width= "Match_parent" 39 android:layout_height= "Wrap_content" android:src= "@drawable/bmp4"/>41 <imageview43 Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:src= "@ Drawable/bmp5 "/>46 <imageview48 android:layout_width=" Match_parent "(Android:la) yout_height= "Wrap_content" "android:src=" @drawable/bmp6 "/>51 <imageview53 Andro Id:layout_width= "Match_parent" android:layout_height= "wrap_content" android:src= "@drawable/bmp 7 "/>56 ≪imageview58 android:layout_width= "match_parent" android:layout_height= "Wrap_content" 60 android:src= "@drawable/bmp8"/>61 <imageview63 android:layout_width= "Match_parent" 64 android:layout_height= "Wrap_content" android:src= "@drawable/bmp9"/>66 8 android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android : src= "@drawable/bmp10"/>71 </linearlayout>72 </ScrollView>
Effect Show:
Horizontalscrollview
For Horizontalscrollview, in fact all ideas are similar to ScrollView, the only difference is that Horizontalscrollview support horizontal scrolling. In the above example, just change the peripheral scrollview to Horizontalscrollview, and then wrap the LinearLayout android:o The Rientation property is set to horizontal to achieve a horizontal scrolling effect. Because there is no new technical content, the demo code is no longer present here.
Effect Show:
SOURCE download
Summarize
For today's Android development, most applications that need to use scrolling effects, such as sliding display news effects, will use the ListView to load the data directly. But ScrollView still has a certain use, such as some of the properties of the software settings, can be placed in a scrollview. The core idea is that for some dynamic effect display, use the ListView, for fixed some effect display, use ScrollView parcel can.
Please support the original, respect for the original, reproduced please indicate the source. Thank you.
The ScrollView of Android--ui