Android實(shí)現(xiàn)下拉刷新的視圖和圖標(biāo)的旋轉(zhuǎn)
一、下拉才出現(xiàn)的視圖
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屬性,代表進(jìn)程的時(shí)間是否不確定。
2、黃色底的是Android Studio的提示。第一個(gè)提示的是,當(dāng)LinearLayout中的Text拓展得足夠長(zhǎng)時(shí),會(huì)與ImageView重疊,實(shí)際效果是把ImageView給覆蓋了。第二個(gè)是,建議用toStartOf代替toLeftOf,用marginEnd代替marginRight等。原因和影響還沒完全搞懂。
二、圖標(biāo)旋轉(zhuǎn)的動(dòng)畫
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、構(gòu)造方法:
public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
(1)toDegrees - fromDegrees < 0 就會(huì)是逆時(shí)針旋轉(zhuǎn),反之是順時(shí)針。這是我取不同值測(cè)試出來的。水平線右邊是0°,或者360°,左邊是180°,或者是-180°。
(2)pivotType是樞軸類型,也就是旋轉(zhuǎn)中心。RELATIVE_TO_SELF代表相對(duì)這個(gè)view本身。0.5f代表這個(gè)view一半大小的位置。
2、setInterpolator作用是設(shè)置速度器。LinearInterpolator是勻速加速器,也就是勻速播放動(dòng)畫。
3、setDuration作用是設(shè)置動(dòng)畫時(shí)長(zhǎng),以毫秒為單位。
4、setFillAfter作用是,當(dāng)參數(shù)為true時(shí),動(dòng)畫播放完后,view會(huì)維持在最終的狀態(tài)。而默認(rèn)值是false,也就是動(dòng)畫播放完后,view會(huì)恢復(fù)原來的狀態(tài)。
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
- Android實(shí)現(xiàn)底部圖標(biāo)與Fragment的聯(lián)動(dòng)實(shí)例
- Android開發(fā)之APP安裝后在桌面上不顯示應(yīng)用圖標(biāo)的解決方法
- Android 桌面圖標(biāo)右上角顯示未讀消息數(shù)字
- Android如何動(dòng)態(tài)改變App桌面圖標(biāo)
- Android輸入框添加emoje表情圖標(biāo)的實(shí)現(xiàn)代碼
- Android中正確使用字體圖標(biāo)(iconfont)的方法
- Android獲取高清app圖標(biāo)代碼分享
- Android App更改應(yīng)用的圖標(biāo)的實(shí)現(xiàn)方法
相關(guān)文章
Android使用setContentView實(shí)現(xiàn)頁面的轉(zhuǎn)換效果
這篇文章主要介紹了Android如何使用setContentView實(shí)現(xiàn)頁面的轉(zhuǎn)換效果,幫助大家更好的利用Android進(jìn)行開發(fā),感興趣的朋友可以了解下2021-01-01
Android利用LitePal操作數(shù)據(jù)庫存取圖片
這篇文章主要為大家詳細(xì)介紹了Android利用LitePal操作數(shù)據(jù)庫存取圖片的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Android計(jì)步功能的實(shí)現(xiàn)代碼
本篇文章主要介紹了Android計(jì)步功能的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03
使用Android Studio 開發(fā)自己的SDK教程
很多時(shí)候我們要將自己開發(fā)一個(gè)類庫打包成jar包以供他調(diào)用,這個(gè)jar包也叫你自己的SDK或者叫l(wèi)ibrary。android studio生成jar包的方法與eclipse有所不同。在studio中l(wèi)ibrary其實(shí)是module的概念。2017-10-10
Android實(shí)現(xiàn)簡(jiǎn)易瀏覽器遇到問題的解決方法
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易瀏覽器遇到的一系列問題的解決方法,感興趣的小伙伴們可以參考一下2016-06-06
基于barcodescanner實(shí)現(xiàn)Android二維碼掃描功能
這篇文章主要為大家詳細(xì)介紹了基于barcodescanner實(shí)現(xiàn)Android二維碼掃描功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Android列表控件Spinner簡(jiǎn)單用法示例
這篇文章主要介紹了Android列表控件Spinner簡(jiǎn)單用法,結(jié)合實(shí)例形式分析了Android列表控件Spinner的布局與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-12-12

