这期内容当中小编将会给大家带来有关如何在Android中利用ScrollView实现一个顶部悬停效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。原理:原理其实很简单就是对view的Gone和visibl
这期内容当中小编将会给大家带来有关如何在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>
--结束END--
本文标题: 如何在Android中利用ScrollView实现一个顶部悬停效果
本文链接: https://www.lsjlt.com/news/224027.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0