package com.qiangyuyang.demo.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.qiangyuyang.demo.R;
/**
* yangqiangyu on 09/01/2017 22:32
* e-mail:168553877@qq.com
* blog:http://blog.csdn.net/yissan
*/
public class CommonLoadingView extends FrameLayout {
//加载时显示文字
protected TextView mLoadingTextTv;
public Context mContext;
//加载错误视图
protected LinearLayout mLoadErrorLl;
//加载错误点击事件处理
private LoadingHandler mLoadingHandler;
//加载view
private View loadingView;
//加载失败view
private View loadingErrorView;
//数据为空
private View emptyView;
public CommonLoadingView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CommonLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
}
public void setLoadingHandler(LoadingHandler loadingHandler) {
mLoadingHandler = loadingHandler;
}
public void setLoadingErrorView(View loadingErrorView) {
this.removeViewAt(1);
this.loadingErrorView = loadingErrorView;
this.loadingErrorView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mLoadingHandler != null) {
mLoadingHandler.doRequestData();
CommonLoadingView.this.load();
}
}
});
this.addView(loadingErrorView,1);
}
public void setLoadingView(View loadingView) {
this.removeViewAt(0);
this.loadingView = loadingView;
this.addView(loadingView,0);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
loadingView = inflate(mContext, R.layout.common_loading_view, null);
loadingErrorView = inflate(mContext, R.layout.network_layout, null);
emptyView = inflate(mContext, R.layout.empty_layout, null);
this.addView(loadingView);
this.addView(loadingErrorView);
this.addView(emptyView);
loadingErrorView.setVisibility(GONE);
emptyView.setVisibility(GONE);
initView(this);
}
public void setMessage(String message) {
mLoadingTextTv.setText(message);
}
private void initView(View rootView) {
mLoadingTextTv = (TextView) rootView.findViewById(R.id.loading_text_tv);
mLoadErrorLl = (LinearLayout) rootView.findViewById(R.id.load_error_ll);
mLoadErrorLl.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mLoadingHandler != null) {
CommonLoadingView.this.load();
mLoadingHandler.doRequestData();
}
}
});
}
public void load(){
loadingView.setVisibility(VISIBLE);
loadingErrorView.setVisibility(GONE);
emptyView.setVisibility(GONE);
}
public void load(String message){
mLoadingTextTv.setText(message);
loadingView.setVisibility(VISIBLE);
loadingErrorView.setVisibility(GONE);
emptyView.setVisibility(GONE);
}
public void loadSuccess(){
this.loadSuccess(false);
}
public void loadSuccess(boolean isEmpty){
loadingView.setVisibility(GONE);
loadingErrorView.setVisibility(GONE);
if (isEmpty) {
emptyView.setVisibility(VISIBLE);
}else{
emptyView.setVisibility(GONE);
}
}
public void loadError(){
loadingView.setVisibility(GONE);
loadingErrorView.setVisibility(VISIBLE);
}
public interface LoadingHandler{
void doRequestData();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android自定义通用加载view
共89个文件
xml:44个
png:13个
bin:6个
2星 需积分: 49 188 下载量 82 浏览量
2017-01-18
13:59:07
上传
评论 2
收藏 373KB ZIP 举报
温馨提示
1、显示加载视图,加载失败的时候显示加载失败视图,数据为空时显示数据为空视图,支持为失败视图设置点击事件重新加载数据。 2、支持个性化设置,自定义设置 加载、失败、空数据视图。 博客讲解:http://blog.csdn.net/yissan
资源推荐
资源详情
资源评论
收起资源包目录
CommonLoadingView2.zip (89个子文件)
CommonLoadingView2
CommonLoadingView2.iml 872B
gradlew 5KB
settings.gradle 15B
.DS_Store 6KB
.idea
libraries
junit_4_12.xml 467B
support_v4_24_2_1.xml 411B
javax_inject_1.xml 316B
support_fragment_24_2_1.xml 778B
support_vector_drawable_24_2_1.xml 654B
javax_annotation_api_1_2.xml 350B
exposed_instrumentation_api_publish_0_5.xml 714B
hamcrest_library_1_3.xml 334B
espresso_idling_resource_2_2_2.xml 696B
support_core_ui_24_2_1.xml 772B
hamcrest_core_1_3.xml 516B
support_core_utils_24_2_1.xml 790B
support_annotations_24_2_1.xml 535B
jsr305_2_0_1.xml 322B
support_compat_24_2_1.xml 766B
hamcrest_integration_1_3.xml 346B
appcompat_v7_24_2_1.xml 599B
espresso_core_2_2_2.xml 641B
rules_0_5.xml 564B
support_media_compat_24_2_1.xml 802B
javawriter_2_1_1.xml 322B
animated_vector_drawable_24_2_1.xml 659B
runner_0_5.xml 569B
runConfigurations.xml 564B
misc.xml 3KB
compiler.xml 686B
workspace.xml 154KB
gradle.xml 705B
encodings.xml 159B
modules.xml 373B
copyright
profiles_settings.xml 74B
gradle
wrapper
gradle-wrapper.properties 233B
gradle-wrapper.jar 52KB
.gradle
2.14.1
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 21KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.bin 25KB
localClassSetAnalysis.lock 17B
taskArtifacts
fileSnapshotsToTreeSnapshotsIndex.bin 24KB
cache.properties.lock 17B
fileHashes.bin 147KB
taskArtifacts.bin 84KB
fileSnapshots.bin 1.26MB
cache.properties 30B
local.properties 448B
gradlew.bat 2KB
gradle.properties 730B
.gitignore 118B
app
.DS_Store 6KB
src
androidTest
java
com
qiangyuyang
demo
ExampleInstrumentedTest.java 744B
test
java
com
qiangyuyang
demo
ExampleUnitTest.java 398B
main
AndroidManifest.xml 813B
res
mipmap-hdpi
ic_launcher.png 3KB
mipmap-xxxhdpi
ic_launcher.png 10KB
mipmap-xhdpi
ic_launcher.png 5KB
drawable-hdpi
ic_error_outline_grey_800_36dp.png 891B
ic_child_care_blue_grey_800_36dp.png 1KB
mipmap-mdpi
ic_launcher.png 2KB
drawable
corner_dialog.xml 328B
layout
empty_layout.xml 756B
activity_custom_view.xml 500B
network_layout.xml 777B
activity_default_view.xml 962B
common_loading_view.xml 1KB
activity_main.xml 723B
drawable-xxhdpi
ic_error_outline_grey_800_36dp.png 2KB
ic_child_care_blue_grey_800_36dp.png 2KB
drawable-xhdpi
ic_error_outline_grey_800_36dp.png 1KB
ic_child_care_blue_grey_800_36dp.png 1KB
values-w820dp
dimens.xml 358B
values
colors.xml 208B
strings.xml 80B
styles.xml 369B
dimens.xml 211B
drawable-xxxhdpi
ic_error_outline_grey_800_36dp.png 2KB
ic_child_care_blue_grey_800_36dp.png 3KB
mipmap-xxhdpi
ic_launcher.png 8KB
java
com
qiangyuyang
demo
widget
CommonLoadingView.java 4KB
CustomViewActivity.java 2KB
MainActivity.java 1KB
DefaultViewActivity.java 2KB
libs
app.iml 13KB
.gitignore 7B
build.gradle 868B
proguard-rules.pro 677B
build.gradle 498B
共 89 条
- 1
资源评论
- lwjbzgy2018-07-16不怎么样不怎么样
程序员yqy
- 粉丝: 1335
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功