在项目中经常会遇到这样的场合,用户点击了一个界面后要提示等待加载,最后有可能显示加载失败,点击屏幕再重试加载。下面是该实例的代码:

layout: loading.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:background="#eee"
android:id="@+id/loading_error_screen"
> <RelativeLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView
android:id="@+id/loading_img"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/loading_animator"
/> <TextView
android:text="正在加载中..."
android:textSize="18sp"
android:layout_below="@id/loading_img"
android:layout_marginTop="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout> </RelativeLayout>

layout: loading_error.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:background="#eee"
android:id="@+id/loading_error_screen"
android:onClick="reloadContent"
> <RelativeLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView
android:layout_centerHorizontal="true"
android:id="@+id/loading_error_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/wb_request_loading_error"
/> <TextView
android:text="加载失败,请点击屏幕重试"
android:textSize="18sp"
android:layout_below="@id/loading_error_img"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout> </RelativeLayout>

Java:

package com.example.basicUI;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView; /**
* 作者:Heyiyong,2014年2月1日23:53:18
*/
public class LoadingActivity extends Activity {
private ImageView imageView;
AnimationDrawable loadingDrawable; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //模拟加载数据
loadContent();
} /**
* 加载数据
*/
private void loadContent() {
setContentView(R.layout.loding);
//显示加载的那个动画
imageView = (ImageView) findViewById(R.id.loading_img);
loadingDrawable = (AnimationDrawable) imageView.getBackground();
loadingDrawable.start(); new Thread(new Runnable() {
@Override
public void run() {
//模拟加载数据
try {
Thread.sleep(2200);
} catch (InterruptedException e) {
}
runOnUiThread(new Runnable() {
@Override
public void run() {
setContentView(R.layout.loading_error);
}
});
}
}).start();
} /**
* 加载失败的点击事件
*/
public void reloadContent(View view) {
loadContent();
}
}

点击下载源代码

android 点击重新加载界面设计的更多相关文章

  1. 我的Android进阶之旅------>Android疯狂连连看游戏的实现之加载界面图片和实现游戏Activity(四)

    正如在<我的Android进阶之旅------>Android疯狂连连看游戏的实现之状态数据模型(三)>一文中看到的,在AbstractBoard的代码中,当程序需要创建N个Piec ...

  2. java攻城狮之路(Android篇)--widget_webview_metadata_popupwindow_tabhost_分页加载数据_菜单

    一.widget:桌面小控件1 写一个类extends AppWidgetProvider 2 在清单文件件中注册: <receiver android:name=".ExampleA ...

  3. android开发之Fragment加载到一个Activity中

    Fragments 是android3.0以后添加的.主要是为了方便android平板端的开发.方便适应不同大小的屏幕.此代码是为了最简单的Fragment的使用,往一个Activity中添加Frag ...

  4. Android中的动态加载机制

    在目前的软硬件环境下,Native App与Web App在用户体验上有着明显的优势,但在实际项目中有些会因为业务的频繁变更而频繁的升级客户端,造成较差的用户体验,而这也恰恰是Web App的优势.本 ...

  5. wemall app商城源码Android之ListView异步加载网络图片(优化缓存机制)

    wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享wemall app商城源码Android之L ...

  6. Android的ListView异步加载图片时,错位、重复、闪烁问题的分析及解决方法

    Android ListView异步加载图片错位.重复.闪烁分析以及解决方案,具体问题分析以及解决方案请看下文. 我们在使用ListView异步加载图片的时候,在快速滑动或者网络不好的情况下,会出现图 ...

  7. Android 的 so 文件加载机制

    本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 最近碰到一些 so 文件问题,顺便将相关知识点梳理一下. 提问 本文的结论是跟着 System.loadlibrary() 一层层源 ...

  8. android 下的网络图片加载

    Android图片的异步加载,主要原理: 加载图片时先查看缓存中时候存在该图片,如果存在则返回该图片,否则先加载载一个默认的占位图片,同时创建一个通过网络获取图片的任务并添加,任务完成后放松消息给主线 ...

  9. Android高效异步图片加载框架

    概述 Android高效异步图片加载框架:一个高效的异步加载显示的图片加载框架,同时具备图片压缩,缓存机制等特性. 详细 代码下载:http://www.demodashi.com/demo/1214 ...

随机推荐

  1. java坑之无法创建线程

    环境:linux 错误:java.lang.OutOfMemoryError: unable to create new native thread 原因:OS对线程是有限制 解决办法: 在Linux ...

  2. must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int)问题

    依照视屏编写代码如下 class MyButtonListener implements OnClickListener{ @Override public void onClick(View v){ ...

  3. asp.net get server control id from javascript

    var WhateverValue = document.getElementById('<%= saveValue.ClientID %>').value

  4. python学习之html从0开始(一)

    <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...

  5. MySQL基础学习之函数

    数学函数 绝对值      abs() 圆周率      PI() 平方根 sqrt() 模除取余   mod(被除数,除数) 随机数      rand() 四舍五入    round(数字) 次方 ...

  6. PHP的$_SERVER['HTTP_HOST']获取服务器地址功能详解

    uchome的index文件中的二级域名功能判断,使用了php的$_SERVER['HTTP_HOST'],开始对这个不是很了解,所以百度了一下,发现一篇帖子有点意思,转发过来做个记录. 在php中, ...

  7. Spark Streaming揭秘 Day24 Transformation和action图解

    Spark Streaming揭秘 Day24 Transformation和action图解 今天我们进入SparkStreaming的数据处理,谈一下两个重要的操作Transfromation和a ...

  8. .NET基础之深度复制和浅度复制

    之前一直没有搞清楚深度复制和浅度复制的区别到底在哪里,今天彻底把这个东西弄懂了,写出来与到家共勉. 如果大家不懂值类型和引用类型的区别,请先看http://www.cnblogs.com/Autumo ...

  9. Android “NetworkOnMainThreadException”出错原因及解决办法

    原因: 不允许在主线程中通讯 方法1:非要在主线程中,当然也可以,这样去处理: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Build ...

  10. 大批量DML操作应该注意什么?

    问:大批量DML操作应该注意什么? 答:大批量DML操作可能会撑爆undo表空间,导致数据库挂起.因此我们应该设置一个合适的undo表空间,或对DML操作的分批提交.