7.1.4 ScrollView结合案例详解

简介: ScrollView是一个滚动条控件,当屏幕中内容很多时候需要使用滚动条。ScrollView类的继承图如下:<br>java.lang.Object<br>   ↳android.view.View<br>    ↳android.view.ViewGroup<br>    ↳android.widget.FrameLayout<br>    ↳android.widget
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 android:orientation="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 android:orientation="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开发案例驱动教程》第七章
目录
相关文章
Flutter ScrollView嵌套ListView滑动冲突
Flutter ScrollView嵌套ListView滑动冲突
1095 0
ScrollView和HorizontalScrollView无法设置点击事件的源码解析
最近的开发过程中,发现存在ScrollView和HorizontalScrollView无法设置点击事件的现象。 我们知道,通常在设置点击事件时,位于View树上方的子View的OnClickListener,会优先于父View的OnClickListener执行。 开发过程中我们会经常使用类似的方式来给布局设置点击事件,比如给ListView的Item背景设置OnClickListener,用于点击item空白区域的跳转操作;然后再给item内部的子元素分别设置OnClickListener用于各自不同的点击操作。
SwipeRefreshLayout 嵌套ScrollView 滑动冲突
SwipeRefreshLayout 嵌套ScrollView 滑动冲突
206 0
还在为ScrollView嵌套RecyclerView而发愁吗?
还在为ScrollView嵌套RecyclerView而发愁吗?
164 0
scrollview的原理及一些属性(转)
在滚动过程当中,其实是在修改原点坐标 当手指触摸后, scroll view会暂时拦截触摸事件,使用一个 计时器,假如在计时器到点后,没有发生手指移动事件, 那么,scroll view发送tracking events到被点击的subview 假如在...
1099 0
从原理上说说ScrollView嵌套ListView的问题
版权声明:本文为sydMobile原创文章,转载请务必注明出处! https://blog.csdn.net/sydMobile/article/details/79543986 文章最早发布于我的微信公众号 Android_De_Home 中,欢迎大家扫描下面二维码关注微信公众获取更多知识内容。
1030 0
|
Android开发
解决ScrollView嵌套RecyclerView滑动卡顿问题
目前 RecyclerView 的使用已经比较普遍了,当需要嵌套使用 RecyclerView 和 ScrollView 时候滑动卡顿的问题,也遇到的越来越多,特此记录下。
2189 0
|
监控 前端开发 iOS开发