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 】
相关推荐:
奇安信“盘古石”团队突破 iOS 26.1 提权
中山网站推广排名,中山信息港登录入口?
网站图片在线制作软件,怎么在图片上做链接?
香港服务器租用每月最低只需15元?
详解Android中Activity的四大启动模式实验简述
Laravel Asset编译怎么配置_Laravel Vite前端构建工具使用
使用Dockerfile构建java web环境
香港服务器网站卡顿?如何解决网络延迟与负载问题?
UC浏览器如何切换小说阅读源_UC浏览器阅读源切换【方法】
佛山企业网站制作公司有哪些,沟通100网上服务官网?
Laravel事件和监听器如何实现_Laravel Events & Listeners解耦应用的实战教程
百度输入法ai组件怎么删除 百度输入法ai组件移除工具
Internet Explorer官网直接进入 IE浏览器在线体验版网址
Microsoft Edge如何解决网页加载问题 Edge浏览器加载问题修复
Python企业级消息系统教程_KafkaRabbitMQ高并发应用
西安市网站制作公司,哪个相亲网站比较好?西安比较好的相亲网站?
Laravel怎么实现软删除SoftDeletes_Laravel模型回收站功能与数据恢复【步骤】
Laravel辅助函数有哪些_Laravel Helpers常用助手函数大全
如何实现建站之星域名转发设置?
如何用手机制作网站和网页,手机移动端的网站能制作成中英双语的吗?
韩国代理服务器如何选?解析IP设置技巧与跨境访问优化指南
Laravel如何使用Blade组件和插槽?(Component代码示例)
如何自己制作一个网站链接,如何制作一个企业网站,建设网站的基本步骤有哪些?
如何利用DOS批处理实现定时关机操作详解
Laravel怎么多语言本地化设置_Laravel语言包翻译与Locale动态切换【手册】
如何自定义建站之星网站的导航菜单样式?
敲碗10年!Mac系列传将迎来「触控与联网」双革新
Python自然语言搜索引擎项目教程_倒排索引查询优化案例
猎豹浏览器开发者工具怎么打开 猎豹浏览器F12调试工具使用【前端必备】
郑州企业网站制作公司,郑州招聘网站有哪些?
如何用低价快速搭建高质量网站?
Laravel请求验证怎么写_Laravel Validator自定义表单验证规则教程
在线教育网站制作平台,山西立德教育官网?
Laravel怎么实现搜索高亮功能_Laravel结合Scout与Algolia全文检索【实战】
Laravel怎么创建自己的包(Package)_Laravel扩展包开发入门到发布
Laravel如何使用模型观察者?(Observer代码示例)
海南网站制作公司有哪些,海口网是哪家的?
为什么要用作用域操作符_php中访问类常量与静态属性的优势【解答】
悟空识字如何进行跟读录音_悟空识字开启麦克风权限与录音
如何实现javascript表单验证_正则表达式有哪些实用技巧
浅谈Javascript中的Label语句
Laravel如何使用Laravel Vite编译前端_Laravel10以上版本前端静态资源管理【教程】
PHP 500报错的快速解决方法
如何在橙子建站上传落地页?操作指南详解
Linux网络带宽限制_tc配置实践解析【教程】
胶州企业网站制作公司,青岛石头网络科技有限公司怎么样?
电视网站制作tvbox接口,云海电视怎样自定义添加电视源?
美食网站链接制作教程视频,哪个教做美食的网站比较专业点?
如何用PHP快速搭建CMS系统?
厦门模型网站设计制作公司,厦门航空飞机模型掉色怎么办?

