`

Android实现Zaker的加载对话框

阅读更多
[img]

[/img]


自定义的Dialog:
package com.amaker.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class MyProgressDialog extends Dialog {

	private Context context = null;

	private TextView tv_msg;

	public MyProgressDialog(Context context) {
		super(context);
		this.context = context;

	}

	public MyProgressDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {

		super(context, cancelable, cancelListener);
		this.context = context;
		// TODO Auto-generated constructor stub
	}

	public MyProgressDialog(Context context, int theme) {

		super(context, theme);
		this.context = context;
		// 加载自己定义的布局
		View view = LayoutInflater.from(context)
				.inflate(R.layout.loading, null);

		ImageView img_loading = (ImageView) view.findViewById(R.id.img_loading);
		ImageView img_close = (ImageView) view.findViewById(R.id.img_close);
		tv_msg = (TextView) view.findViewById(R.id.tv_msg);
		// 加载XML文件中定义的动画
		RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils
				.loadAnimation(context, R.anim.rotate_refresh_drawable_default);
		// 开始动画
		img_loading.setAnimation(rotateAnimation);
		//为Dialoge设置自己定义的布局
		setContentView(view);
		//为close的那个文件添加事件
		img_close.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				dismiss();

			}
		});

	}

	public void setMsg(String msg) {

		if (null != tv_msg) {
			tv_msg.setText(msg);
		}
	}

	public void setMsg(int resId) {

		if (null != tv_msg) {
			tv_msg.setText(context.getString(resId));
		}
	}

}


MainActivity:
package com.amaker.dialog;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	MyProgressDialog progressDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button btn = (Button) findViewById(R.id.button1);
        
        btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				progressDialog = new MyProgressDialog(MainActivity.this,  
		                R.style.CustomProgressDialog);  
				progressDialog.show();

			}
		});
    }
}


loading.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg"
    >
   
<TextView  
	android:id="@+id/tv_msg" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="正在加载。。。"
    />
<ImageView 
	android:id="@+id/img_loading" 
	android:layout_height="wrap_content" 
	android:layout_width="wrap_content" 
	android:src="@drawable/test"></ImageView>

<ImageView 
	android:id="@+id/img_close" 
	android:layout_height="wrap_content" 
	android:layout_width="wrap_content" 
	android:src="@drawable/icon"></ImageView>
</LinearLayout>


styles.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
	 <style name="CustomDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    </style>

    <style name="CustomProgressDialog" parent="@style/CustomDialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowNoTitle">true</item>
    </style>
	
</resources>



rotate_refresh_drawable_default.xml(动画)
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="800"
    android:fromDegrees="0.0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50.0%"
    android:pivotY="50.0%"
    android:repeatCount="infinite"
    android:toDegrees="360.0" />
  • 大小: 36.3 KB
分享到:
评论

相关推荐

    模仿Zaker加载框

    在Android开发中,模仿Zaker加载框涉及到的是UI设计与动画效果的实现。Zaker是一款知名的资讯阅读应用,它的加载框通常是指在内容加载时显示的动态效果,以提高用户体验,让用户知道应用正在处理数据。这里我们将...

    Android 仿zaker效果的拖拽排序.zip

    在Android开发中,实现类似Zaker应用的拖拽排序功能是一项常见的需求,它能提供用户友好的交互体验,使得用户可以自由调整列表或网格中的元素顺序。本项目名为"Android 仿zaker效果的拖拽排序.zip",其核心是实现了...

    android仿zaker效果demo.zip

    【标题】"android仿zaker效果demo.zip"指的是一个Android开发项目,它的目标是实现一个类似于ZAKER新闻阅读应用的效果。ZAKER是一款流行的新闻资讯应用,以其优雅的界面设计和流畅的用户体验著称。这个Demo旨在提供...

    类似zaker中的加载视图

    在Android应用开发中,"类似Zaker中的加载视图"是指模仿Zaker这款新闻阅读应用在加载文章时显示的自定义进度对话框(ProgressDialog)。Zaker以其优秀的用户体验和个性化设计受到用户喜爱,其中加载视图是提升用户体验...

    Android 仿zaker效果demo(不使用用gridview).rar

    本示例项目“Android 仿zaker效果demo(不使用用gridview)”旨在实现类似的效果,但避免使用GridView,而是采用其他方法来实现更灵活的布局和滚动体验。 首先,Zaker的主界面通常包含多个新闻模块,每个模块由标题...

    Android 仿zaker效果demo(不使用用gridview).zip

    在Android开发中,有时我们需要创建类似ZAKER新闻应用的界面效果,这个"Android 仿zaker效果demo(不使用用gridview)"就是一个很好的学习资源。ZAKER以其优雅的布局和流畅的用户体验著称,而这个项目则尝试通过不...

    android仿zaker效果demo(不使用用gridview).rar

    在这个“android仿zaker效果demo”中,开发者选择不使用GridView,而是通过其他方式实现类似的效果,这可能涉及到自定义布局、RecyclerView或者其他列表控件。 1. **自定义布局(Custom Layout)**: 在不使用...

    Android仿zaker效果demo不使用用gridview.zip

    这个"Android仿zaker效果demo不使用gridview.zip"是一个示例项目,它展示了如何在Android应用程序中实现类似ZAKER的界面,但并未使用传统的GridView组件。 1. **自定义布局(Custom Layout)**: 在不使用GridView...

    Android仿zaker用手向上推动的特效开发【推动门效果】(附demo源码下载)

    【Android 仿Zaker手势上滑特效开发——推动门效果详解】 在Android应用开发中,为用户界面添加独特的交互效果可以提升用户体验。Zaker是一款知名的新闻阅读应用,其特色之一就是用户通过上滑手势来“推开”首页的...

    Android 仿zaker效果demo(不使用用gridview)-IT计算机-毕业设计.zip

    在本项目中,"Android 仿zaker效果demo(不使用用gridview)"是一个针对Android平台的应用开发实例,旨在模仿知名资讯阅读应用Zaker的功能和界面设计,但并未使用常见的GridView组件。这个Demo适用于那些正在学习...

    Android 仿zaker效果demo(不使用用gridview).zip项目安卓应用源码下载

    Android 仿zaker效果demo(不使用用gridview).zip项目安卓应用源码下载Android 仿zaker效果demo(不使用用gridview).zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发...

    ZAKER 风格主界面实现

    总的来说,"ZAKER风格主界面实现"项目涵盖了移动应用开发中的多个核心知识点,包括UI设计、布局管理、触摸事件处理、数据加载和UI组件的使用。开发者需要熟练掌握这些技能,才能打造出既美观又功能丰富的用户界面。...

    安卓动画效果相关-Android仿zaker效果的拖拽排序.rar

    这个“安卓动画效果相关-Android仿zaker效果的拖拽排序.rar”文件包含了实现类似ZAKER拖拽排序功能的代码示例。 拖拽排序是一种允许用户通过触摸屏幕并拖动项目来更改其顺序的交互方式。在安卓平台上,这种功能主要...

    Android代码-仿zaker效果demo不使用用gridview.zip

    在Android开发中,"仿Zaker效果"通常指的是创建一个类似新闻阅读应用的界面,它具有清晰的布局、丰富的媒体内容展示以及用户友好的交互体验。Zaker是一款知名的资讯阅读应用,其界面设计深受开发者们的青睐,常被...

    android安卓仿zaker界面源码wp风格

    "android安卓仿zaker界面源码wp风格"这个标题表明这是一个关于Android平台的项目,其目标是模仿Zaker应用的用户界面,并采用了Windows Phone(WP)的界面设计风格。Zaker是一款知名的新闻阅读应用,以其简洁、易用的...

    android拖拽效果仿zaker 优化性能版本

    在Android开发中,实现类似Zaker的拖拽效果是一项挑战性的任务,特别是在追求高性能和流畅度的同时。这个“android拖拽效果仿zaker 优化性能版本”项目旨在提供一种优化的解决方案,使得用户在浏览内容时能享受到...

    Android应用源码高仿小米launcher(ZAKER)跨屏拖动.zip

    在Android应用开发中,"高仿小米launcher(ZAKER)跨屏拖动"是一个常见的实践,旨在为用户提供类似小米手机启动器或ZAKER新闻应用那样的交互体验。这份源码提供了实现这一功能的详细步骤和代码,对于想要深入理解...

    Android源码——仿zaker效果demo(不使用用gridview).zip

    这个"Android源码——仿zaker效果demo(不使用用gridview)"的项目,就是针对这一需求的一个示例实现,它展示了如何在不使用GridView的情况下构建类似ZAKER的应用界面。下面将详细介绍这个项目的重点知识点。 首先...

Global site tag (gtag.js) - Google Analytics