Android实现下拉刷新的视图和图标的旋转

发布时间 - 2026-01-10 23:26:21    点击率:

一、下拉才出现的视图

pull_to_refresh_header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pull_to_refresh_header"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F3F3F3">
 <RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingTop="23dp">
  <LinearLayout 
       android:id="@+id/pull_to_refresh_view"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:layout_centerHorizontal="true">
   <TextView
android:id="@+id/pull_to_refresh_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
android:text="@string/pull_to_refresh_text"
    android:textColor="#777777"
    android:textSize="16sp"/>
   <TextView
android:id="@+id/pull_to_refresh_update_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
android:text="@string/pull_to_refresh_update_text"
    android:textColor="#999999"
    android:textSize="14sp"/>
  </LinearLayout>
  <ProgressBar
android:id="@+id/pull_to_refresh_progress"
   android:layout_width="30dp"
   android:layout_height="30dp"
android:layout_toLeftOf="@id/pull_to_refresh_view"
   android:layout_marginRight="22dp"
   android:layout_marginTop="5dp"
   android:indeterminate="true"
android:indeterminateDrawable="@drawable/ic_loading_refresh"
   android:visibility="gone"/>
  <ImageView
   android:id="@+id/pull_to_refresh_image"
   android:layout_width="32dp"
   android:layout_height="32dp"
android:layout_toLeftOf="@id/pull_to_refresh_view"
   android:layout_marginRight="20dp"
   android:layout_marginTop="5dp"
   android:src="@drawable/ic_refresh_down"
   android:scaleType="centerInside"
android:contentDescription="@string/app_name"/>
 </RelativeLayout>
 <View
  android:layout_width="match_parent"
  android:layout_height="15dp"/>
</LinearLayout>

ic_loading_refresh.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
 android:drawable="@drawable/ic_loading"
 android:fromDegrees="0"
 android:toDegrees="360"
 android:pivotX="50%"
 android:pivotY="50%" />

1、ProgressBar的indeterminate属性,代表进程的时间是否不确定。

2、黄色底的是Android Studio的提示。第一个提示的是,当LinearLayout中的Text拓展得足够长时,会与ImageView重叠,实际效果是把ImageView给覆盖了。第二个是,建议用toStartOf代替toLeftOf,用marginEnd代替marginRight等。原因和影响还没完全搞懂。

二、图标旋转的动画

private ImageView mPull_to_refresh_image;
private RotateAnimation mFlipAnimation;

...

  mFlipAnimation = new RotateAnimation(0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
    RotateAnimation.RELATIVE_TO_SELF, 0.5f);
  mFlipAnimation.setInterpolator(new LinearInterpolator());
  mFlipAnimation.setDuration(250);
  mFlipAnimation.setFillAfter(true);

...
mPull_to_refresh_image.startAnimation(mFlipAnimation);

1、构造方法:

public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,
   int pivotYType, float pivotYValue)

(1)toDegrees - fromDegrees < 0 就会是逆时针旋转,反之是顺时针。这是我取不同值测试出来的。水平线右边是0°,或者360°,左边是180°,或者是-180°。

(2)pivotType是枢轴类型,也就是旋转中心。RELATIVE_TO_SELF代表相对这个view本身。0.5f代表这个view一半大小的位置。

2、setInterpolator作用是设置速度器。LinearInterpolator是匀速加速器,也就是匀速播放动画。

3、setDuration作用是设置动画时长,以毫秒为单位。

4、setFillAfter作用是,当参数为true时,动画播放完后,view会维持在最终的状态。而默认值是false,也就是动画播放完后,view会恢复原来的状态。

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!


# android实现下拉刷新  # android实现图标的旋转  # Android实现底部图标与Fragment的联动实例  # Android开发之APP安装后在桌面上不显示应用图标的解决方法  # Android 桌面图标右上角显示未读消息数字  # Android如何动态改变App桌面图标  # Android输入框添加emoje表情图标的实现代码  # Android中正确使用字体图标(iconfont)的方法  # Android获取高清app图标代码分享  # Android App更改应用的图标的实现方法  # 的是  # 完后  # 就会  # 还没  # 第一个  # 这是我  # 第二个  # 或者是  # 不确定  # 时长  # 默认值  # 顺时针  # dp  # TextView  # true  # layout_centerHorizontal  # pull_to_refresh_view  # background  # wrap_content  # text 


相关栏目: 【 网站优化151355 】 【 网络推广146373 】 【 网络技术251813 】 【 AI营销90571


相关推荐: Python文件流缓冲机制_IO性能解析【教程】  如何用免费手机建站系统零基础打造专业网站?  lovemo网页版地址 lovemo官网手机登录  Thinkphp 中 distinct 的用法解析  使用spring连接及操作mongodb3.0实例  利用vue写todolist单页应用  米侠浏览器网页背景异常怎么办 米侠显示修复  Laravel怎么为数据库表字段添加索引以优化查询  php485函数参数是什么意思_php485各参数详细说明【介绍】  HTML5空格和nbsp有啥关系_nbsp的作用及使用场景【说明】  Windows10如何删除恢复分区_Win10 Diskpart命令强制删除分区  如何在Tomcat中配置并部署网站项目?  Java垃圾回收器的方法和原理总结  Laravel如何使用Laravel Vite编译前端_Laravel10以上版本前端静态资源管理【教程】  怎么用AI帮你为初创公司进行市场定位分析?  企业网站制作这些问题要关注  Laravel怎么清理缓存_Laravel optimize clear命令详解  Laravel定时任务怎么设置_Laravel Crontab调度器配置  Laravel如何使用Collections进行数据处理?(实用方法示例)  iOS中将个别页面强制横屏其他页面竖屏  如何在浏览器中启用Flash_2025年继续使用Flash Player的方法【过时】  如何用AI帮你把自己的生活经历写成一个有趣的故事?  🚀拖拽式CMS建站能否实现高效与个性化并存?  韩国代理服务器如何选?解析IP设置技巧与跨境访问优化指南  JavaScript数据类型有哪些_如何准确判断一个变量的类型  Laravel如何实现多对多模型关联?(Eloquent教程)  Laravel如何使用Socialite实现第三方登录?(微信/GitHub示例)  Laravel如何创建和注册中间件_Laravel中间件编写与应用流程  猪八戒网站制作视频,开发一个猪八戒网站,大约需要多少?或者自己请程序员,需要什么程序员,多少程序员能完成?  实例解析angularjs的filter过滤器  详解CentOS6.5 安装 MySQL5.1.71的方法  Windows10电脑怎么查看硬盘通电时间_Win10使用工具检测磁盘健康  瓜子二手车官方网站在线入口 瓜子二手车网页版官网通道入口  如何在万网自助建站平台快速创建网站?  手机网站制作与建设方案,手机网站如何建设?  教你用AI润色文章,让你的文字表达更专业  ChatGPT怎么生成Excel公式_ChatGPT公式生成方法【指南】  Win11搜索栏无法输入_解决Win11开始菜单搜索没反应问题【技巧】  Laravel API路由如何设计_Laravel构建RESTful API的路由最佳实践  公司网站制作需要多少钱,找人做公司网站需要多少钱?  音乐网站服务器如何优化API响应速度?  黑客如何通过漏洞一步步攻陷网站服务器?  Laravel项目如何进行性能优化_Laravel应用性能分析与优化技巧大全  Claude怎样写约束型提示词_Claude约束提示词写法【教程】  java ZXing生成二维码及条码实例分享  高防服务器如何保障网站安全无虞?  Laravel怎么在Controller之外的地方验证数据  Laravel如何实现模型的全局作用域?(Global Scope示例)  Laravel如何生成API文档?(Swagger/OpenAPI教程)  今日头条AI怎样推荐抢票工具_今日头条AI抢票工具推荐算法与筛选【技巧】