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

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. 什么是C++标准库?

    C++中的标准程序库(简称标准库)是类库和函数的集合,其使用核心语言写成.标准程序库提供若干泛型容器.函数对象.泛型字符串和流(包含交互和文件I/O),支持部分语言特性和常用的函数,如开平方根.C++ ...

  2. PHP学习笔记 - 进阶篇(2)

    PHP学习笔记 - 进阶篇(2) 函数 1.自定义函数 PHP内置了超过1000个函数,因此函数使得PHP成为一门非常强大的语言.大多数时候我们使用系统的内置函数就可以满足需求,但是自定义函数通过将一 ...

  3. Xcode7主题路径

    // Xcode7主题路径~/Library/Developer/Xcode/UserData/FontAndColorThemes

  4. iOS常用的设计模式

    iOS常用的设计模式有:单例模式.委托模式.观察者模式和MVC模式.下面分别简单介绍. 一:单例模式 我们常用的UIApplication.NSUserdefaults.NSNotificationC ...

  5. (转)SQLSERVER表分区的介绍(一)

    下面进入正题吧,很多时候当单张数据表的数据量比较大的时候比如千万级别条记录.上亿级别记录,如果不做优化,那么查询的效率大家清楚. 有经验的人会通过各种手段做优化,其中表分区就是其中一种手段. 个人对表 ...

  6. 老老实实学习WCF[第二篇] 配置wcf

    老老实实学WCF 第二篇 配置WCF 在上一篇中,我们在一个控制台应用程序中编写了一个简单的WCF服务并承载了它.先回顾一下服务端的代码: using System; using System.Col ...

  7. IPoint从自定义的投影坐标系转换到自定义的地理坐标系

    IPoint pointStart = new PointClass(); pointStart = xyPolyline.FromPoint; ISpatialReferenceFactory pS ...

  8. makefile --文件文档经链接使用

    生成.a 文件是什么? 在makefile的设置使得文件文档可以方便的使用,不用特意的加某些头文件 加入某些产生的链接包

  9. linux find 反转 查找没有被找到的结果

    在linux下,有时候需要找一些文件,还有时候这些文件格式不够统一和规范,但是需要排除的那些文件却格式统一,就可以使用find命令的反转功能 一般用find查找文件的命令是: find . -name ...

  10. jquery横向滚动条

    此代码献给wendy 由于工作太忙,下次再整理成插件调用,先记录下来,欢迎同学们提意见. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...