农村四月闲人少,勤学苦攻把名扬。这篇文章主要讲述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 { 15private ProgressWheel mPbProgressBar; 16public ImageView mTvTipState; 17private TextView mTvTipMsg; 18 19private Context context; 20 21public TipInfoLayout(Context context) { 22super(context); 23this.context = context; 24initView(context); 25} 26 27public TipInfoLayout(Context context, AttributeSet attrs) { 28super(context, attrs); 29this.context = context; 30initView(context); 31} 32 33public TipInfoLayout(Context context, AttributeSet attrs, int defStyleAttr) { 34super(context, attrs, defStyleAttr); 35this.context = context; 36initView(context); 37} 38 39private void initView(Context context) { 40View view = LayoutInflater.from(context).inflate(R.layout.core_tip_info_layout, null, false); 41mPbProgressBar = (ProgressWheel) view.findViewById(R.id.tv_tip_loading); 42mTvTipState = (ImageView) view.findViewById(R.id.tv_tip_state); 43mTvTipMsg = (TextView) view.findViewById(R.id.tv_tip_msg); 44setLoading(); 45 //completeLoading(); 46addView(view); 47} 48 49/*public void setOnClick(OnClickListener onClik) { 50this.setOnClickListener(onClik); 51}*/ 52 53public void setLoading() { 54setLoading(context.getString(R.string.tip_loading)); 55} 56 57public void setLoading(String message) { 58//this.setVisibility(VISIBLE); 59this.mPbProgressBar.setVisibility(View.VISIBLE); 60this.mTvTipState.setVisibility(View.GONE); 61this.mTvTipMsg.setVisibility(View.VISIBLE); 62this.mTvTipMsg.setText(context.getString(R.string.tip_loading)); 63} 64 65/** 66* 完成加载 67*/ 68public void completeLoading(){ 69this.mPbProgressBar.setVisibility(View.GONE); 70this.mTvTipState.setVisibility(View.GONE); 71this.mTvTipMsg.setVisibility(View.GONE); 72} 73 74public void setNetworkError() { 75this.mPbProgressBar.setVisibility(View.GONE); 76this.mTvTipState.setVisibility(View.VISIBLE); 77this.mTvTipState.setImageResource(R.drawable.core_page_icon_network); 78this.mTvTipMsg.setVisibility(View.VISIBLE); 79this.mTvTipMsg.setText(context.getString(R.string.tip_load_network_error)); 80} 81 82public void setLoadError(String message){ 83setLoadError(); 84this.mTvTipMsg.setText(message); 85} 86 87public void setLoadError() { 88this.mPbProgressBar.setVisibility(View.GONE); 89this.mTvTipState.setVisibility(View.VISIBLE); 90this.mTvTipState.setImageResource(R.drawable.core_page_icon_loaderror); 91this.mTvTipMsg.setVisibility(View.VISIBLE); 92this.mTvTipMsg.setText(context.getString(R.string.tip_load_error)); 93} 94 95public void setEmptyData(String message){ 96setEmptyData(); 97this.mTvTipMsg.setText(message); 98} 99 100public void setEmptyData() { 101this.setVisibility(VISIBLE); 102this.mPbProgressBar.setVisibility(View.GONE); 103this.mTvTipState.setVisibility(View.VISIBLE); 104this.mTvTipState.setImageResource(R.drawable.core_page_icon_empty); 105this.mTvTipMsg.setVisibility(View.VISIBLE); 106this.mTvTipMsg.setText(context.getString(R.string.tip_load_empty)); 107} 108 109/** 110* 不显示任何提示 111*/ 112public void setCancelShow(){ 113this.mPbProgressBar.setVisibility(View.GONE); 114this.mTvTipState.setVisibility(View.GONE); 115this.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" 3android:layout_width="match_parent" 4android:layout_height="match_parent"> 5 6< com.wuxianedu.wxhlcorelibrary.widget.RefreshLayout 7android:id="@+id/refreshLayout" 8android:layout_width="wrap_content" 9android:layout_height="wrap_content"> 10< ListView android:id="@+id/lv_liebiao" 11android:layout_width="match_parent" 12android:layout_height="match_parent" /> 13< /com.wuxianedu.wxhlcorelibrary.widget.RefreshLayout> 14< com.wuxianedu.wxhlcorelibrary.widget.TipInfoLayout 15android:id="@+id/tipInfoLayout_id" 16android:layout_width="match_parent" 17android:layout_height="match_parent"/> 18 19 20 < /RelativeLayout>
之后在java文件中初始化他
1 tipInfoLayout = (TipInfoLayout) view.findViewById(R.id.tipInfoLayout_id);
//开始加载
tipInfoLayout.setLoading();
//完成加载
tipInfoLayout.completeLoading();
【Android学习笔记--实现正在加载圆圈,加完完成自动取消】
推荐阅读
- Android开发艺术探索——第二章(IPC机制(中))
- Android性能优化之巧用软引用与弱引用优化内存使用
- 从高处理解android与服务器交互(看懂了做开发就会非常的容易)
- 利用videoView创建播放器,实现展示视频列表和搜索sd卡功能 以及android6.0的动态授权等功能
- Android 手机卫士10--应用管理器
- 录制Android手机操作,转换为Gif图
- 移动开发安卓Lab2(02)
- Objective-C实现双向链表、栈和队列 – Objective-C开发教程
- Accolite面试经验|S20(校园内)