职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 376|回复: 1

7.1.4 ScrollView结合案例详解

[复制链接]
紫衿 发表于 2011-8-25 09:58 | 显示全部楼层 |阅读模式
ScrollView......
推荐链接 20-30......


ScrollView是一个滚动条控件,当屏幕中内容很多时候需要使用滚动条。ScrollView类的继承图如下:
java.lang.Object
   ?android.view.View
   ?android.view.ViewGroup
   ?android.widget.FrameLayout
   ?android.widget.ScrollView
android.widget.ScrollView继承了android.widget.FrameLayout框架布局类。ScrollView例子如图7-9所示滚动条例子。
  


图7-9 Scrollview
布局文件请参考代码清单7-10,完整代码请参考chapter7_1工程中scrollview_1.xml代码部分(chapter7_1/res/layout/scrollview_1.xml)。
【代码清单7-10】
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout androidrientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
android:textSize="20dip" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/content" />
</LinearLayout>
</ScrollView>
ScrollView有很多属性管理它的样式,如果在xml中设置,可以在<ScrollView >标签内设置滚动条样式的属性:
? android:scrollbars="none",不显示滚动条,但能够滚动的;
? android:scrollbarSize,滚动条大小。
修改上面的例子添加这些属性xml布局文件代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbarSize="12dip"
    android:scrollbars="none"
    >
<LinearLayout androidrientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello"
android:textSize="20dip" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/content" />
</LinearLayout>
</ScrollView>
                                      出自《Android开发案例驱动教程》第七章

大小: 36.2 KB
查看图片附件

北大青鸟 发表于 2011-8-25 09:59 | 显示全部楼层
推荐链接
20-30万急聘多名天才Java/MTA软件工程师
见证又一个准百万富翁的诞生!
3G培训就业月薪平均7K+,不3K就业不花一分钱!


您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-4-28 04:28 , Processed in 0.129533 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表