广告
返回顶部
首页 > 资讯 > 精选 >如何在Android中利用ScrollView实现一个顶部悬停效果
  • 855
分享到

如何在Android中利用ScrollView实现一个顶部悬停效果

androidscrollviewroi 2023-05-31 06:05:58 855人浏览 泡泡鱼
摘要

这期内容当中小编将会给大家带来有关如何在Android中利用ScrollView实现一个顶部悬停效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。原理:原理其实很简单就是对view的Gone和visibl

这期内容当中小编将会给大家带来有关如何在Android中利用ScrollView实现一个顶部悬停效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

原理:

原理其实很简单就是对view的Gone和visible,写两个相同的要置顶的view,一个设置为gone,一个为visible,当可见的view超出屏幕范围的时候,将不可以的view设置为visible,不可见的view 与scrollview要同级,这样滑动的时候不会影响到view的位置。

直接上代码

<&#63;xml version="1.0" encoding="utf-8"&#63;><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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作