Android君子剑之ScrollView之君子好逑
来源:互联网 发布:cad迷你看图mac版下载 编辑:程序博客网 时间:2024/04/27 17:20
传送门 ☞ Android兵器谱 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229
君子剑
窈窕淑女,君子好逑。英雄美人,君子淑女,郎才女貌,珠联璧合。梁思成、林徽因结婚,有人赠联:梁上君子,林下美人。月明林下美人来。
今天我们学习如何利用Android平台“君子剑”ScrollView实现垂直滚动浏览信息的功能,ScrollView使用起来非常简单,和HorizontalScrollView正好是一对“冤家”。下面给出该情景的案例:
一、案例技术要点
1.ScorllView控件中摆放一个LinearLayout。不能嵌套摆放其他支持滚动的控件。
2.设置LinearLayout按照垂直方向布局
android:orientation="vertical"
3.LinearLayout布局中所有控件的总高度必须大于屏幕高度。
二、案例代码陈列
工程包目录
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.lynn.scrollview" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <activity android:name=".ScrollViewMainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>strings.xml
<resources> <string name="app_name">Android垂直滚动ScrollView</string> <string name="view">垂直滚动视图</string> <string name="more">显示更多</string></resources>main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/view" android:textSize="24sp" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/item1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/more" android:textSize="24sp" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/item2" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/item3" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/item4" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/item5" /> </LinearLayout></ScrollView>
ScrollViewMainActivity.java
package cn.lynn.scrollview;import android.app.Activity;import android.os.Bundle;/** * ScrollView支持垂直滚动,并且在ScrollView中只能放置一个控件,通常是一个LinearLayout。 * 另外,该LinearLayout必须采用垂直布局。当LinearLayout中摆放的控件所占用的总高度大于屏幕高度时, * 就会在屏幕右侧出现一个滚动条。 * ScrollView案例:垂直滚动浏览信息 * @author lynnli1229 */public class ScrollViewMainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}
三、案例效果展示
- Android君子剑之ScrollView之君子好逑
- 君子之交淡若水
- 君子之行
- 君子之道
- android之ScrollView
- android控件之ScrollView
- android组件之ScrollView
- Android 之ScrollView
- Android 笔记之ScrollView
- Android UI之ScrollView
- Android之ScrollView
- Android散打之ScrollView
- Android-UI之ScrollView
- Android之ScrollView
- Android--UI之ScrollView
- 我有君子之质,无君子之能
- 君子之形与小人之质
- Android学习笔记之ScrollView
- Effective Java读书笔记 第二章: Creating And Destroying Objects
- Firebird嵌入版本的使用方法
- [VB.NET]在win服务中添加自动起动服务,每隔五分钟触发一次
- Oracle查询用户所有表
- vb.net 从进程获取窗体
- Android君子剑之ScrollView之君子好逑
- Tomcat无法shutdown SEVERE: BAD packet signature
- java文件读写操作大全
- VMware9虚拟机安装MAC OS X Mountain Lion 10.8.2详细图文教程
- dbx 常用命令
- Python之道–LEGB法则
- html5学习笔记---01.HTML5介绍,02.HTML5的新特性
- 创建一个既可作为普通exe(双击能运行),又可作为服务运行的程序
- android:ListView:convertView.setTag()来设置数据