返回
顶部

修改密码

Android启动界面的实现

+1

-1

收藏

+1

-1

点赞0

评论0

01 package wht.android.loading;02 03 import android.content.Context;04 import android.graphics.Canvas;05 import android.util.AttributeSet;06 import android.widget.ImageView;07 08 public class LoadingView extends ImageView implements Runnable09 {10 …
 
 
01 package wht.android.loading;
02
03 import android.content.Context;
04 import android.graphics.Canvas;
05 import android.util.AttributeSet;
06 import android.widget.ImageView;
07
08 public class LoadingView extends ImageView implements Runnable
09 {
10        private boolean isStop = false;
11        
12        private int[] imageIds;
13        private int index = 0;
14        private int length = 1;
15        
16        public LoadingView(Context context)
17        {
18                this(context, null);
19        }
20
21        public LoadingView(Context context, AttributeSet attrs)
22        {
23                super(context, attrs);
24        }
25        
26        public void setImageIds(int[] imageId)
27        {
28                this.imageIds = imageId;
29                if(imageIds != null && imageIds.length > 0)
30                {
31                        length = imageIds.length;
32                }
33        }
34        
35                @Override
36        protected void onDetachedFromWindow()
37        {
38                // TODO Auto-generated method stub
39                super.onDetachedFromWindow();
40                isStop = true;
41        }
42
43        @Override
44        protected void onDraw(Canvas canvas)
45        {
46                // TODO Auto-generated method stub
47                super.onDraw(canvas);
48                if(imageIds != null && imageIds.length > 0)
49                {
50                        this.setImageResource(imageIds[index]);
51                }
52        }
53
54        @Override
55        public void run()
56        {
57                while(!isStop)
58                {
59                        index = ++index % length;
60                        postInvalidate();
61                        try
62                        {
63                                Thread.sleep(400);
64                        }
65                        catch (InterruptedException e)
66                        {
67                                e.printStackTrace();
68                        }
69                }
70        }
71        
72        public void startAnim()
73        {
74                new Thread(this).start();
75        }
76
77 }
 
 
01 package wht.android.loading;
02
03 import android.app.Activity;
04 import android.os.Bundle;
05
06 public class MainActivity extends Activity
07 {
08    
09    private LoadingView main_imageview;
10    
11    @Override
12    public void onCreate(Bundle savedInstanceState)
13    {
14        super.onCreate(savedInstanceState);
15        setContentView(R.layout.main);
16        main_imageview = (LoadingView)findViewById(R.id.main_imageview);
17        initLoadingImages();
18        
19        new Thread()
20        {
21            @Override
22            public void run()
23            {
24                main_imageview.startAnim();
25            }
26        }.start();
27        
28    }
29    
30    private void initLoadingImages()
31    {
32        int[] imageIds = new int[6];
33        imageIds[0] = R.drawable.loader_frame_1;
34        imageIds[1] = R.drawable.loader_frame_2;
35        imageIds[2] = R.drawable.loader_frame_3;
36        imageIds[3] = R.drawable.loader_frame_4;
37        imageIds[4] = R.drawable.loader_frame_5;
38        imageIds[5] = R.drawable.loader_frame_6;
39        
40        main_imageview.setImageIds(imageIds);
41    }
42 }
 
 
01 <?xml version="1.0" encoding="utf-8"?>
02 <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
03        android:orientation="vertical"android:layout_width="fill_parent"
04        android:layout_height="fill_parent"android:background="#e1e1e1">
05        <wht.android.loading.LoadingView
06                android:layout_gravity="center_horizontal"android:layout_height="wrap_content"
07                android:id="@+id/main_imageview"android:src="@drawable/loader_frame_1"
08                android:layout_marginTop="190dp"android:layout_width="wrap_content"
09                ></wht.android.loading.LoadingView>
10
11 <TextView
12        android:layout_width="wrap_content"
13        android:layout_height="wrap_content"
14        android:text="启动中..."
15        android:layout_marginTop="10dip"
16        android:textColor="#666666"
17        android:layout_gravity="center_horizontal"
18        android:textSize="20sp"
19 />
20 </LinearLayout>
 

扫一扫在手机打开

评论
已有0条评论
0/150
提交
热门评论
相关推荐
android启动界面 android软件开发教程
  • Splash/启动界面
  • 2022-05-20 18:29
  • 0 0 0
+1
Android Splash界面支持用户点击 直接进入主界面
  • Splash/启动界面
  • 2022-05-20 18:29
  • 0 0 0
+1
在Android中创建启动界面
  • Splash/启动界面
  • 2022-05-20 18:29
  • 0 0 0
+1
Android启动界面的实现
  • Splash/启动界面
  • 2022-05-20 18:29
  • 0 0 0
+1
今日要闻
换一批
热点排行