zl程序教程

您现在的位置是:首页 >  其他

当前栏目

7.1.4 ScrollView结合案例详解

案例 详解 结合 ScrollView 7.1
2023-09-14 08:59:50 时间
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开发案例驱动教程》第七章

ScrollView和HorizontalScrollView无法设置点击事件的源码解析 最近的开发过程中,发现存在ScrollView和HorizontalScrollView无法设置点击事件的现象。 我们知道,通常在设置点击事件时,位于View树上方的子View的OnClickListener,会优先于父View的OnClickListener执行。 开发过程中我们会经常使用类似的方式来给布局设置点击事件,比如给ListView的Item背景设置OnClickListener,用于点击item空白区域的跳转操作;然后再给item内部的子元素分别设置OnClickListener用于各自不同的点击操作。
我们应该都有用过这个功能,你的朋友微信给你分享了一个淘宝里面的商品链接,然后当你复制这个链接打开淘宝APP的时候,就会弹出一个弹窗,像这样: example.PNG 这个功能想必大家都挺熟悉,受这个启发我们产品也想在我们APP上添加这样一个功能,与这个不一样的是,当我们复制一段网址的时候打开我们的APP会弹出框填一些信息后上传到我们的“资源库”。
在滚动过程当中,其实是在修改原点坐标 当手指触摸后, scroll view会暂时拦截触摸事件,使用一个 计时器,假如在计时器到点后,没有发生手指移动事件, 那么,scroll view发送tracking events到被点击的subview 假如在...
文章最早发布于我的微信公众号 Android_De_Home 中,欢迎大家扫描下面二维码关注微信公众获取更多知识内容。
目前 RecyclerView 的使用已经比较普遍了,当需要嵌套使用 RecyclerView 和 ScrollView 时候滑动卡顿的问题,也遇到的越来越多,特此记录下。
关东升 国内著名iOS/Cocos技术作家,iOS技术顾问,Cocos最有价值专家(CVP),智捷课堂首席培训专家。担任51CTO社区iOS技术顾问。 著有多部移动开发畅销书。