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

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. Swift下标

    还记得字典吗? var numberOfLegs= ["spider": 8,"ant": 6, "cat":4] numberOfLegs ...

  2. <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

    转自这里   出 错原因:设置app的状态栏样式的使用使用了旧的方式,在info.plist里面设置了View controller- based status bar appearance为NO,默 ...

  3. HotSpot算法实现

    1.枚举根节点 可作为GC Roots的节点主要在全局性的引用(例如常量或类静态属性)与执行上下文(例如栈帧中的本地变量表)中. 可达性分析对执行时间的敏感体现在GC停顿上,因为分析工作必须在能确保一 ...

  4. java学习笔记_MIDI

    import javax.sound.midi.*; public class Midi { public void play(int instrument, int note) { try { Se ...

  5. jquery实现视觉滚动--fullpage

    用fullpage.js实现视觉滚动效果 1.Html页面 <!DOCTYPE html> <html> <head> <meta charset=" ...

  6. MySQL和Navicat使用总结

    1.给字段设置默认字符值 ALTER TABLE `v_users`MODIFY COLUMN `picture` varchar(50) CHARACTER SET utf8 COLLATE utf ...

  7. maven增量编译

    最近由于不清楚maven(2.2.x)增量编译的机制,导致应用出现了一个当时觉得非常诡异的一个问题.先描述一下问题.     背景是应用A有一个公用的base包,版本为1.6.6-SNAPSHOT,应 ...

  8. PHP中CURL技术模拟登陆抓取网站信息,用与微信公众平台成绩查询

    伴随微信的红火,微信公众平台成为许多开发者的下一个目标.笔者本身对于这种新鲜事物没有如此多的吸引力.但是最近有朋友帮忙开发微信公众平台中一个成绩查询的功能.于是便在空余时间研究了一番. 主要的实现步骤 ...

  9. Wpf 简单制作自己的窗体样式(2)

    上一篇blog讲了制作简单的样式的窗体,对于一个传统的窗体,不仅仅可以拖动,和关闭操作.还具有最大化.最小化.隐藏,以及改变窗体的大小等.这篇blog就是对上篇的补充,完善窗体的改变大小和最大化最小化 ...

  10. Custom Control

    How to create custom control http://www.silverlightshow.net/items/Creating-a-Silverlight-Custom-Cont ...