2013年8月13日星期二

Android

 

Introduction

 

this blog and HorizontalScrollView ScrollView mainly on the use of two containers. They represent the vertical scrolling and horizontal scrolling, scrolling the contents of which contain a View. In this brief introduction will ScrollView and HorizontalScrollView use and precautions, and finally to a simple Demo to demonstrate the use of the two containers.

 

ScrollView

 

ScrollView , inheritance through official documents can be seen, it inherits from FrameLayout, so it is a special type of FrameLayout, because it can use a user scrolls through the display larger than the physical space occupied by the list view display. Notably, ScrollView can contain only one child view or view group, the actual project, usually contains a vertical LinearLayout.

 

is worth noting that, ScrollView and ListView can not be used together, because ListView vertically scrolling already done a deal, it would force the ListView content if the content is larger than the physical view of the time, forcing vertical scrolling effect, so here Using ScrollView and ListView mix is ​​pointless, for the ListView explain, you can see another one of my blog: Android - UI of the ListView. EditText ScrollView also need to pay attention that comes with multi-line input scrolling effect, but also can not mix, if in ScrollView contains multiple rows EditText, EditText that comes rolling in effect will lapse. The central idea is that ScrollView scroll view is a container comes with a scrolling effect for some of the controls, and it can not be used together are mixed.

 

on the Android platform, and there is a HorizontalScrollView ScrollView similar container, the container with ScrollView opposite effect, mainly for horizontal scrolling, understanding ScrollView basically understand HorizontalScrollView, so here is focused on the use of ScrollView.

 

Example Demo

 

ScrollView is actually a layout, so basically nothing much their own methods or properties require special explanation. Demo here to demonstrate a direct use and the effect can explain, here are the ten pictures, 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 <LinearLayout
7 android:layout_width="match_parent"
8 android:layout_height="wrap_content"
9 android:orientation="vertical" >
10
11 <TextView
12 android:layout_width="match_parent"
13 android:layout_height="wrap_content"
14 android:text="垂直滚动视图"
15 android:textSize="30dp" />
16
17 <ImageView
18 android:layout_width="match_parent"
19 android:layout_height="wrap_content"
20 android:src="@drawable/bmp1" />
21
22 <ImageView
23 android:layout_width="match_parent"
24 android:layout_height="wrap_content"
25 android:src="@drawable/bmp2" />
26
27 <ImageView
28 android:layout_width="match_parent"
29 android:layout_height="wrap_content"
30 android:src="@drawable/bmp3" />
31
32 <EditText
33 android:maxLines="2"
34 android:layout_width="match_parent"
35 android:layout_height="40dp" />
36
37 <ImageView
38 android:layout_width="match_parent"
39 android:layout_height="wrap_content"
40 android:src="@drawable/bmp4" />
41
42 <ImageView
43 android:layout_width="match_parent"
44 android:layout_height="wrap_content"
45 android:src="@drawable/bmp5" />
46
47 <ImageView
48 android:layout_width="match_parent"
49 android:layout_height="wrap_content"
50 android:src="@drawable/bmp6" />
51
52 <ImageView
53 android:layout_width="match_parent"
54 android:layout_height="wrap_content"
55 android:src="@drawable/bmp7" />
56
57 <ImageView
58 android:layout_width="match_parent"
59 android:layout_height="wrap_content"
60 android:src="@drawable/bmp8" />
61
62 <ImageView
63 android:layout_width="match_parent"
64 android:layout_height="wrap_content"
65 android:src="@drawable/bmp9" />
66
67 <ImageView
68 android:layout_width="match_parent"
69 android:layout_height="wrap_content"
70 android:src="@drawable/bmp10" />
71 </LinearLayout>
72
73 </ScrollView>
 
 

results show:

 

 

 

HorizontalScrollView

 

For HorizontalScrollView , in fact, all our thoughts are with ScrollView similar, the only difference is HorizontalScrollView supports horizontal scrolling. In the above example, only need to change the external ScrollView as HorizontalScrollView, then wrapped LinearLayout where the android: orientation property set to horizontal scroll horizontally to achieve the effect. Because there is nothing new technical content, there will no longer show Demo code.

 

results show:

 

 

source download

 

Summary

 

For now, Android developers, most of the applications, the need to use the rolling effect when, for example, the effect of sliding News will directly use the ListView to load data. But there are still some use ScrollView, such as some software attributes set, you can be placed in a ScrollView. Core idea is to show some of the dynamic effects, use ListView, for a fixed number of results show, on the use ScrollView parcel can be.

 

Please support the original, respect for the original, reproduced please indicate the source. Thank you.

没有评论:

发表评论