«

android 加载的一些收藏

时间:2024-3-2 18:43     作者:韩俊     分类: Android


第一种普通的ProgressBar:

<ProgressBar
        android:id="@+id/right_progress"
        style="?android:attr/progressBarStyleSmall" 
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginRight="15.0dip"
        android:indeterminateDrawable="@drawable/pro" />

这里的style="?android:attr/progressBarStyleSmall"是指小号圆形的progressbar

android:indeterminateDrawable="@drawable/pro"是指设置绘制不显示进度的进度条的Drawable对象

所指的pro.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >
        <gradient
            android:centerColor="#DAA520" 
            android:centerY="0.50"
            android:endColor="#DAA520" 
            android:startColor="#000000"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>
效果如下:



常见的Android的ProgressBar样式:
style="?android:attr/progressBarStyleHorizontal"  长形进度条

style="?android:attr/progressBarStyleLarge"   超大号圆形ProgressBar

style="?android:attr/progressBarStyleSmall" 小号圆形ProgressBar

style="?android:attr/progressBarStyleSmallTitle" 标题型圆形ProgressBar
第二种带动态的ProgressBar
package com.example.logindialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class LoadingDialog extends Dialog {
    private static final int CHANGE_TITLE_WHAT = 1;
    private static final int CHNAGE_TITLE_DELAYMILLIS = 300;
    private static final int MAX_SUFFIX_NUMBER = 3;
    private static final char SUFFIX = '.';

    private ImageView iv_route;
    private TextView tv;
    private TextView tv_point;
    private RotateAnimation mAnim;
    private boolean cancelable = true;

    private Handler handler = new Handler(){
        private int num = 0;

        public void handleMessage(android.os.Message msg) {
            if (msg.what == CHANGE_TITLE_WHAT) {
                StringBuilder builder = new StringBuilder();
                if (num >= MAX_SUFFIX_NUMBER) {
                    num = 0;
                }
                num ++;
                for (int i = 0;i < num;i++) {
                    builder.append(SUFFIX);
                }
                tv_point.setText(builder.toString());               
                if (isShowing()) {
                    handler.sendEmptyMessageDelayed(CHANGE_TITLE_WHAT, CHNAGE_TITLE_DELAYMILLIS);
                } else {
                    num = 0;
                }
            }
        };
    };

    public LoadingDialog(Context context) {
        super(context, R.style.Dialog_bocop);//1
        init();
    }

    private void init() {
        View contentView = View.inflate(getContext(), R.layout.activity_custom_loding_dialog_layout, null);
        setContentView(contentView);

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cancelable) {
                    dismiss();
                }
            }
        });
        iv_route = (ImageView) findViewById(R.id.iv_route);
        tv = (TextView) findViewById(R.id.tv);
        tv_point = (TextView) findViewById(R.id.tv_point);
        initAnim();
        getWindow().setWindowAnimations(R.anim.alpha_in);
    }

    private void initAnim() {
        mAnim = new RotateAnimation(360, 0,Animation.RESTART, 0.5f, Animation.RESTART,0.5f);
        mAnim.setDuration(2000);
        mAnim.setRepeatCount(Animation.INFINITE);
        mAnim.setRepeatMode(Animation.RESTART);
        mAnim.setStartTime(Animation.START_ON_FIRST_FRAME);
    }

    @Override
    public void show() {
        iv_route.startAnimation(mAnim);
        handler.sendEmptyMessage(CHANGE_TITLE_WHAT);
        super.show();
    }

    @Override
    public void dismiss() {
        mAnim.cancel();
        super.dismiss();
    }

    @Override
    public void setCancelable(boolean flag) {
        cancelable = flag;
        super.setCancelable(flag);
    }

    @Override
    public void setTitle(CharSequence title) {
        tv.setText(title);
    }

    @Override
    public void setTitle(int titleId) {
        setTitle(getContext().getString(titleId));
    }
}

所需要的一个样式:R.style.Dialog_bocop如下
 <!-- Loding_dialog样式Start -->
    <style name="Dialog_bocop">
        <item name="android:windowBackground">@color/bocop_dialog_bg</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@+android:style/Animation.Dialog</item>
    </style>

R.layout.activity_custom_loding_dialog_layout如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <LinearLayout
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:layout_gravity="center"
        android:background="@drawable/dialog_bocop_loaing_bg"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:gravity="center" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:padding="3dp"
                android:src="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/iv_route"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:background="@drawable/dialog_bocop_loading_rotate_anim_img" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:gravity="center_horizontal" >

            <TextView
                android:id="@+id/tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:text="正在加载"
                android:gravity="center"
                android:textColor="#6F6868"
                android:textSize="20sp"
                android:layout_toLeftOf="@+id/tv_point"
                android:singleLine="true"
                 />

            <TextView
                android:id="@+id/tv_point"
                android:layout_width="20dp"
                android:layout_height="wrap_content"
                android:text="..."
                android:textColor="#6F6868"
                android:textSize="20sp"
                android:layout_alignParentRight="true" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

alpha_in.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="1000"
    >
</alpha>
让我们来看看activity,其实很简单:
package com.example.logindialog;

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 {

    private Button btn_logining = null;
    private LoadingDialog mLoadingDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mLoadingDialog = new LoadingDialog(this);
        btn_logining = (Button) findViewById(R.id.btn_logining);
        btn_logining.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mLoadingDialog.show(); 
            }
        });
    }
}
来看看结果吧:

第三种加载dialog动画: 先看看运行出来的效果是咋滴:

自定义的Dialog如下:

package com.example.dialog;

import com.ant.liao.GifView;
import com.ant.liao.GifView.GifImageType;
import android.os.Bundle;
import android.app.Dialog;
import android.content.Context;
import android.view.Window;
import android.widget.TextView;

public class MyDialog extends Dialog{
    private Context context;
    private static  GifView gifView;
    private TextView tv;
    String conent; 

    public MyDialog(Context context, int theme,String content) {
        super(context, theme);
        this.context = context;
        this.conent=content; 
    } 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.setContentView(R.layout.dialog);
        gifView=(GifView)findViewById(R.id.gifView22);
        gifView.setGifImageType(GifImageType.WAIT_FINISH); 
        gifView.setGifImage(R.drawable.loading);
    }

}

activity是这样写的:
package com.example.dialog;

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

public class MainActivity extends Activity {
    Dialog   dialog;
    private Button  mbtn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        dialog=new MyDialog(this, 0, null);
        mbtn=(Button)findViewById(R.id.btn);
        mbtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dialog.show();
            }
        });
    }
}
就是这么多了,简单吧!


资源下载链接:

http://download.csdn.net/detail/hehaiminginadth/8795629

标签: android

热门推荐