首页 > 代码库 > Android 启动界面的实现(转载)
Android 启动界面的实现(转载)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | package wht.android.loading; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.widget.ImageView; public class LoadingView extends ImageView implements Runnable { private boolean isStop = false ; private int [] imageIds; private int index = 0 ; private int length = 1 ; public LoadingView(Context context) { this (context, null ); } public LoadingView(Context context, AttributeSet attrs) { super (context, attrs); } public void setImageIds( int [] imageId) { this .imageIds = imageId; if (imageIds != null && imageIds.length > 0 ) { length = imageIds.length; } } @Override protected void onDetachedFromWindow() { // TODO Auto-generated method stub super .onDetachedFromWindow(); isStop = true ; } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super .onDraw(canvas); if (imageIds != null && imageIds.length > 0 ) { this .setImageResource(imageIds[index]); } } @Override public void run() { while (!isStop) { index = ++index % length; postInvalidate(); try { Thread.sleep( 400 ); } catch (InterruptedException e) { e.printStackTrace(); } } } public void startAnim() { new Thread( this ).start(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | package wht.android.loading; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { private LoadingView main_imageview; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); main_imageview = (LoadingView)findViewById(R.id.main_imageview); initLoadingImages(); new Thread() { @Override public void run() { main_imageview.startAnim(); } }.start(); } private void initLoadingImages() { int [] imageIds = new int [ 6 ]; imageIds[ 0 ] = R.drawable.loader_frame_1; imageIds[ 1 ] = R.drawable.loader_frame_2; imageIds[ 2 ] = R.drawable.loader_frame_3; imageIds[ 3 ] = R.drawable.loader_frame_4; imageIds[ 4 ] = R.drawable.loader_frame_5; imageIds[ 5 ] = R.drawable.loader_frame_6; main_imageview.setImageIds(imageIds); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:background = "#e1e1e1" > < wht.android.loading.LoadingView android:layout_gravity = "center_horizontal" android:layout_height = "wrap_content" android:id = "@+id/main_imageview" android:src = "@drawable/loader_frame_1" android:layout_marginTop = "190dp" android:layout_width = "wrap_content" ></ wht.android.loading.LoadingView > < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "启动中..." android:layout_marginTop = "10dip" android:textColor = "#666666" android:layout_gravity = "center_horizontal" android:textSize = "20sp" /> </ LinearLayout > |
Android 启动界面的实现(转载)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。