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)程的時間是否不確定。
2、黃色底的是Android Studio的提示。第一個提示的是,當(dāng)LinearLayout中的Text拓展得足夠長時,會與ImageView重疊,實(shí)際效果是把ImageView給覆蓋了。第二個是,建議用toStartOf代替toLeftOf,用marginEnd代替marginRight等。原因和影響還沒完全搞懂。
二、圖標(biāo)旋轉(zhuǎn)的動畫
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 就會是逆時針旋轉(zhuǎn),反之是順時針。這是我取不同值測試出來的。水平線右邊是0°,或者360°,左邊是180°,或者是-180°。
(2)pivotType是樞軸類型,也就是旋轉(zhuǎn)中心。RELATIVE_TO_SELF代表相對這個view本身。0.5f代表這個view一半大小的位置。
2、setInterpolator作用是設(shè)置速度器。LinearInterpolator是勻速加速器,也就是勻速播放動畫。
3、setDuration作用是設(shè)置動畫時長,以毫秒為單位。
4、setFillAfter作用是,當(dāng)參數(shù)為true時,動畫播放完后,view會維持在最終的狀態(tài)。而默認(rèn)值是false,也就是動畫播放完后,view會恢復(fù)原來的狀態(tài)。
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
- Android實(shí)現(xiàn)底部圖標(biāo)與Fragment的聯(lián)動實(shí)例
- Android開發(fā)之APP安裝后在桌面上不顯示應(yīng)用圖標(biāo)的解決方法
- Android 桌面圖標(biāo)右上角顯示未讀消息數(shù)字
- Android如何動態(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漲姿勢知識點(diǎn)之你沒用過的BadgeDrawable
現(xiàn)在Android中有許多的應(yīng)用仿蘋果的在應(yīng)用圖標(biāo)上顯示小紅點(diǎn),下面這篇文章主要給大家介紹了關(guān)于Android漲姿勢知識點(diǎn)之你沒用過的BadgeDrawable的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09Android Flutter自適應(yīng)瀑布流案例詳解
這篇文章主要介紹了Android Flutter自適應(yīng)瀑布流案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09Flutter 如何設(shè)置App的主色調(diào)與字體
App 開發(fā)過程中,肯定希望給用戶帶來一致的體驗(yàn),這其中最基礎(chǔ)的就是色調(diào)、字體保持一致。在 Flutter 中,可以設(shè)置全局的主題色調(diào)和字體,從而在其他頁面引用主色調(diào)和字體,實(shí)現(xiàn)頁面展示層面的一致。2021-05-05Android Studio 3.0 原生支持kotlin 例子詳解
這篇文章主要介紹了 Android Studio 3.0 原生支持kotlin 例子詳解,非常具有實(shí)用價值,需要的朋友可以參考下2017-05-05Android動畫之漸變動畫(Tween Animation)詳解 (漸變、縮放、位移、旋轉(zhuǎn))
這篇文章主要介紹了Android動畫之漸變動畫(Tween Animation)用法,結(jié)合實(shí)例形式詳細(xì)分析了Android漸變動畫Tween Animation實(shí)現(xiàn)漸變,縮放,位移,旋轉(zhuǎn)等技巧,需要的朋友可以參考下2016-01-01android使用ViewPager組件實(shí)現(xiàn)app引導(dǎo)查看頁面
這篇文章主要為大家詳細(xì)介紹了android使用ViewPager組件實(shí)現(xiàn)app引導(dǎo)查看頁面,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07Android 8.0不能自動安裝APK問題的解決方法(完美適配)
這篇文章主要給大家介紹了關(guān)于Android 8.0不能自動安裝APK問題的解決方法(完美適配),這里的自動安裝是指下載完成后,自動彈出安裝界面,而不是靜默安裝APK,文中介紹的非常詳細(xì),需要的朋友可以參考下2018-07-07