android 点击重新加载界面设计
在项目中经常会遇到这样的场合,用户点击了一个界面后要提示等待加载,最后有可能显示加载失败,点击屏幕再重试加载。下面是该实例的代码:
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 点击重新加载界面设计的更多相关文章
- 我的Android进阶之旅------>Android疯狂连连看游戏的实现之加载界面图片和实现游戏Activity(四)
正如在<我的Android进阶之旅------>Android疯狂连连看游戏的实现之状态数据模型(三)>一文中看到的,在AbstractBoard的代码中,当程序需要创建N个Piec ...
- java攻城狮之路(Android篇)--widget_webview_metadata_popupwindow_tabhost_分页加载数据_菜单
一.widget:桌面小控件1 写一个类extends AppWidgetProvider 2 在清单文件件中注册: <receiver android:name=".ExampleA ...
- android开发之Fragment加载到一个Activity中
Fragments 是android3.0以后添加的.主要是为了方便android平板端的开发.方便适应不同大小的屏幕.此代码是为了最简单的Fragment的使用,往一个Activity中添加Frag ...
- Android中的动态加载机制
在目前的软硬件环境下,Native App与Web App在用户体验上有着明显的优势,但在实际项目中有些会因为业务的频繁变更而频繁的升级客户端,造成较差的用户体验,而这也恰恰是Web App的优势.本 ...
- wemall app商城源码Android之ListView异步加载网络图片(优化缓存机制)
wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享wemall app商城源码Android之L ...
- Android的ListView异步加载图片时,错位、重复、闪烁问题的分析及解决方法
Android ListView异步加载图片错位.重复.闪烁分析以及解决方案,具体问题分析以及解决方案请看下文. 我们在使用ListView异步加载图片的时候,在快速滑动或者网络不好的情况下,会出现图 ...
- Android 的 so 文件加载机制
本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 最近碰到一些 so 文件问题,顺便将相关知识点梳理一下. 提问 本文的结论是跟着 System.loadlibrary() 一层层源 ...
- android 下的网络图片加载
Android图片的异步加载,主要原理: 加载图片时先查看缓存中时候存在该图片,如果存在则返回该图片,否则先加载载一个默认的占位图片,同时创建一个通过网络获取图片的任务并添加,任务完成后放松消息给主线 ...
- Android高效异步图片加载框架
概述 Android高效异步图片加载框架:一个高效的异步加载显示的图片加载框架,同时具备图片压缩,缓存机制等特性. 详细 代码下载:http://www.demodashi.com/demo/1214 ...
随机推荐
- Oracle学习第二天---Profile的使用
环境:Oracle 11g 一.权限的传递 1.如果传递的是对象权限,就在后面加入with grant option: eg:system用户有张temp的表,只想usertest用户拥有查询的权限, ...
- 第六篇、微信小程序-form组件
表单: 将组件内的用户输入的<switch/> <input/> <checkbox/> <slider/> <radio/> <pi ...
- 第五篇、微信小程序-swiper组件
常用属性: 效果图: swiper.wxml添加代码: <swiper indicator-dots="{{indicatorDots}}" autoplay="{ ...
- JavaScript学习笔记(13)——BOM
1.window 所有浏览器都支持window对象,它表示浏览器窗口本身. 所有 JavaScript 全局对象.函数以及变量均自动成为 window 对象的成员. 全局变量是 window 对象的属 ...
- 使用C#通过调用minitab的COM库自动化生成报表
本文介绍通过C#调用minitab com组建自动化生成报表的方法. 首先需要在minitab中通过手动配置的方式生成报表来得到该报表的命令行,过程如下 选择菜单“编辑器”->“启用命令”启用命 ...
- css笔记——移动端
苹果手机 /*按钮样式:*/input[type=button], input[type=submit], input[type=file], button { cursor: pointer; -w ...
- mysql主从集群定时备份脚本
#!/bin/bash dpath="/mysql_backup" mydays="7" username="root" mysql_p ...
- Linux防火墙基本知识
一.防火墙的分类 (一).包过滤防火墙. 数据包过滤(packet Filtering)技术是在网络层对数据包进行选择,选择的依据是系统内设置的过滤逻辑,称为访问控制表(access control ...
- TweenMax动画库学习(一)
目录 TweenMax动画库学习(一) TweenMax动画库学习(二) TweenMax动画库学习(三) Tw ...
- 连接Oracle数据库的OracleHelper.cs
using System; using System.Configuration; using System.Data; using System.Data.OracleClient; using S ...