这期内容当中小编将会给大家带来有关如何在Android中利用ScrollView实现一个顶部悬停效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
原理:
原理其实很简单就是对view的gone和visible,写两个相同的要置顶的view,一个设置为gone,一个为visible,当可见的view超出屏幕范围的时候,将不可以的view设置为visible,不可见的view 与scrollview要同级,这样滑动的时候不会影响到view的位置。
直接上代码
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.lanmai.ObservableScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 中间就是填充的view就不写了--> <!--指定要置顶的view--> <TextView android:id="@+id/specific_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/holo_red_dark" android:gravity="center" android:text="text" android:textSize="40sp"/> <TextView android:layout_width="match_parent" android:layout_height="200dp" android:background="@android:color/darker_gray" android:gravity="center" android:text="text" android:textSize="40sp"/> </LinearLayout> </RelativeLayout> </com.lanmai.ObservableScrollView> <!--指定要置顶的相同的view visibility设置为gone --> <TextView android:id="@+id/specific_text_view_gone" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/holo_red_dark" android:gravity="center" android:text="text" android:textSize="40sp" android:visibility="gone"/> </RelativeLayout>
本文标题:如何在Android中利用ScrollView实现一个顶部悬停效果-创新互联
网站路径:https://www.cdcxhl.com/article8/coidip.html
成都网站建设公司_创新互联,为您提供微信公众号、服务器托管、品牌网站设计、做网站、手机网站建设、建站公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联