Android学习笔记--实现正在加载圆圈,加完完成自动取消
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android学习笔记--实现正在加载圆圈,加完完成自动取消相关的知识,希望对你有一定的参考价值。
今天学到了,网络加载数据 没加载之前是显示正在加载,加载之后 正在加载四个字消失不见,这里要用到一个自定义控件
TipInfoLayout.java 这个是自定义组件的代码 复制粘贴就好
1 package com.wuxianedu.wxhlcorelibrary.widget; 2 3 import android.content.Context; 4 import android.util.AttributeSet; 5 import android.view.LayoutInflater; 6 import android.view.View; 7 import android.widget.FrameLayout; 8 import android.widget.ImageView; 9 import android.widget.TextView; 10 11 import com.pnikosis.materialishprogress.ProgressWheel; 12 import com.wuxianedu.wxhlcorelibrary.R; 13 14 public class TipInfoLayout extends FrameLayout { 15 private ProgressWheel mPbProgressBar; 16 public ImageView mTvTipState; 17 private TextView mTvTipMsg; 18 19 private Context context; 20 21 public TipInfoLayout(Context context) { 22 super(context); 23 this.context = context; 24 initView(context); 25 } 26 27 public TipInfoLayout(Context context, AttributeSet attrs) { 28 super(context, attrs); 29 this.context = context; 30 initView(context); 31 } 32 33 public TipInfoLayout(Context context, AttributeSet attrs, int defStyleAttr) { 34 super(context, attrs, defStyleAttr); 35 this.context = context; 36 initView(context); 37 } 38 39 private void initView(Context context) { 40 View view = LayoutInflater.from(context).inflate(R.layout.core_tip_info_layout, null, false); 41 mPbProgressBar = (ProgressWheel) view.findViewById(R.id.tv_tip_loading); 42 mTvTipState = (ImageView) view.findViewById(R.id.tv_tip_state); 43 mTvTipMsg = (TextView) view.findViewById(R.id.tv_tip_msg); 44 setLoading(); 45 // completeLoading(); 46 addView(view); 47 } 48 49 /*public void setOnClick(OnClickListener onClik) { 50 this.setOnClickListener(onClik); 51 }*/ 52 53 public void setLoading() { 54 setLoading(context.getString(R.string.tip_loading)); 55 } 56 57 public void setLoading(String message) { 58 //this.setVisibility(VISIBLE); 59 this.mPbProgressBar.setVisibility(View.VISIBLE); 60 this.mTvTipState.setVisibility(View.GONE); 61 this.mTvTipMsg.setVisibility(View.VISIBLE); 62 this.mTvTipMsg.setText(context.getString(R.string.tip_loading)); 63 } 64 65 /** 66 * 完成加载 67 */ 68 public void completeLoading(){ 69 this.mPbProgressBar.setVisibility(View.GONE); 70 this.mTvTipState.setVisibility(View.GONE); 71 this.mTvTipMsg.setVisibility(View.GONE); 72 } 73 74 public void setNetworkError() { 75 this.mPbProgressBar.setVisibility(View.GONE); 76 this.mTvTipState.setVisibility(View.VISIBLE); 77 this.mTvTipState.setImageResource(R.drawable.core_page_icon_network); 78 this.mTvTipMsg.setVisibility(View.VISIBLE); 79 this.mTvTipMsg.setText(context.getString(R.string.tip_load_network_error)); 80 } 81 82 public void setLoadError(String message){ 83 setLoadError(); 84 this.mTvTipMsg.setText(message); 85 } 86 87 public void setLoadError() { 88 this.mPbProgressBar.setVisibility(View.GONE); 89 this.mTvTipState.setVisibility(View.VISIBLE); 90 this.mTvTipState.setImageResource(R.drawable.core_page_icon_loaderror); 91 this.mTvTipMsg.setVisibility(View.VISIBLE); 92 this.mTvTipMsg.setText(context.getString(R.string.tip_load_error)); 93 } 94 95 public void setEmptyData(String message){ 96 setEmptyData(); 97 this.mTvTipMsg.setText(message); 98 } 99 100 public void setEmptyData() { 101 this.setVisibility(VISIBLE); 102 this.mPbProgressBar.setVisibility(View.GONE); 103 this.mTvTipState.setVisibility(View.VISIBLE); 104 this.mTvTipState.setImageResource(R.drawable.core_page_icon_empty); 105 this.mTvTipMsg.setVisibility(View.VISIBLE); 106 this.mTvTipMsg.setText(context.getString(R.string.tip_load_empty)); 107 } 108 109 /** 110 * 不显示任何提示 111 */ 112 public void setCancelShow(){ 113 this.mPbProgressBar.setVisibility(View.GONE); 114 this.mTvTipState.setVisibility(View.GONE); 115 this.mTvTipMsg.setVisibility(View.GONE); 116 } 117 }
之后我们在布局里面用到它
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <com.wuxianedu.wxhlcorelibrary.widget.RefreshLayout 7 android:id="@+id/refreshLayout" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content"> 10 <ListView android:id="@+id/lv_liebiao" 11 android:layout_width="match_parent" 12 android:layout_height="match_parent" /> 13 </com.wuxianedu.wxhlcorelibrary.widget.RefreshLayout> 14 <com.wuxianedu.wxhlcorelibrary.widget.TipInfoLayout 15 android:id="@+id/tipInfoLayout_id" 16 android:layout_width="match_parent" 17 android:layout_height="match_parent"/> 18 19 20 </RelativeLayout>
之后在java文件中初始化他
1 tipInfoLayout = (TipInfoLayout) view.findViewById(R.id.tipInfoLayout_id);
//开始加载
tipInfoLayout.setLoading();
//完成加载
tipInfoLayout.completeLoading();
以上是关于Android学习笔记--实现正在加载圆圈,加完完成自动取消的主要内容,如果未能解决你的问题,请参考以下文章