国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android仿ios加載loading菊花圖效果

2019-10-21 21:38:36
字體:
供稿:網(wǎng)友

項目中經(jīng)常會用到加載數(shù)據(jù)的loading顯示圖,除了設(shè)計根據(jù)app自身設(shè)計的動畫loading,一般用的比較多的是仿照ios 的菊花加載loading 圖,當(dāng)然一些條件下還會涉及到加載成功/ 失敗情況的顯示,還有顯示文字。

Android,ios,加載,loading Android,ios,加載,loading

使用ProgressBar 來加載動畫轉(zhuǎn)圈,這里使用drawable文件 定義轉(zhuǎn)圈動畫, indeterminateDrawable 屬性進行加載。

<?xml version="1.0" encoding="utf-8"?><animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"  android:drawable="@mipmap/load"  android:pivotX="50%"  android:pivotY="50%" /><ProgressBar  android:id="@+id/progressBar"  android:layout_width="50dp"  android:layout_height="50dp"  android:indeterminateDrawable="@drawable/anim" />

部分情況下,在加載成功/ 失敗之后會顯示對應(yīng)的靜態(tài)圖片,所以一開始想直接通過 setIndeterminateDrawable(Drawable d) 來加載靜態(tài)圖片,但是直接寫是顯示不出圖片的,還要設(shè)置Drawable 的位置 d.setBounds(Rect bounds) ,即使這樣加載出了靜態(tài)圖片,但是設(shè)置 R.drawable.anim 的轉(zhuǎn)圈動畫時 卻沒有了轉(zhuǎn)圈的效果,好氣喲 ~~

所以在自定義view 的布局里 成功/失敗的狀態(tài)單獨用 imageView 顯示

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="110dp"  android:layout_height="110dp"  android:background="@drawable/shape_dialog_bg"  android:gravity="center"  android:orientation="vertical">  <ProgressBar    android:id="@+id/progressBar"    android:layout_width="50dp"    android:layout_height="50dp"    android:indeterminateDrawable="@drawable/anim" />  <ImageView    android:id="@+id/iv"    android:visibility="gone"    android:layout_width="50dp"    android:layout_height="50dp" />  <TextView    android:id="@+id/tv"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginTop="10dp"    android:text="正在加載"    android:textColor="#fff" /></LinearLayout>

自定義view,提供三種狀態(tài)的方法。

public class LoadingView extends LinearLayout {  ...構(gòu)造函數(shù)...  /**   * loading   */  public void showLoading() {    iv.setVisibility(GONE);    progressBar.setVisibility(VISIBLE);  }  /**   * 成功   */  public void showSuccess() {    iv.setImageResource(R.mipmap.load_success);    iv.setVisibility(View.VISIBLE);    progressBar.setVisibility(GONE);  }  /**   *失敗   */  public void showFail() {    iv.setImageResource(R.mipmap.load_fail);    iv.setVisibility(View.VISIBLE);    progressBar.setVisibility(GONE);  }  /**   * 提示文字   *   * @param txt string   */  public void setText(String txt) {    tv.setText(txt);  }  /**   * 提示文字   */  public void setText(@StringRes int txtId) {    tv.setText(txtId);  }}

效果圖:

Android,ios,加載,loading

github地址: https://github.com/taixiang/loading

總結(jié)

以上所述是小編給大家介紹的Android仿ios加載loading菊花圖效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對VEVB武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 获嘉县| 马尔康县| 甘泉县| 什邡市| 略阳县| 武汉市| 宾阳县| 仁寿县| 元氏县| 泸西县| 温宿县| 天祝| 景德镇市| 兴义市| 大名县| 土默特左旗| 昆明市| 习水县| 刚察县| 灌南县| 调兵山市| 新丰县| 枣庄市| 民勤县| 奈曼旗| 济南市| 万载县| 南宁市| 波密县| 土默特左旗| 罗源县| 新安县| 厦门市| 沧源| 北辰区| 毕节市| 玛沁县| 师宗县| 荣昌县| 修文县| 绍兴市|