android 加载时闪烁点样式的启动画面
16lz
2021-01-26
代码介绍:
模仿UC等软甲加载时检测网络的闪烁点效果,具体美化交给大家自己了,希望大家能有用的上
代码如下:
public class MainActivity extends Activity { /** Called when the activity is first created. */ private int count = 5; private int[] imgIDs = {R.id.widget29,R.id.widget30,R.id.widget31,R.id.widget32,R.id. widget33}; private int INDEX_SELECTED = 0; private final int EDIT_TYPE_SELECTED = 1; //选中的 private final int EDIT_TYPE_NO_SELECTED = 2; //未选中的 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final IndexThread thread = new IndexThread(); for(int id : imgIDs) ((ImageView)findViewById(id)).setBackgroundResource(R.drawable.progress_bg_small); thread.start(); Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { thread.flag = false; } }); } public Handler myHandler = new Handler() { @Override public void handleMessage(Message msg) { Log.i("Test","---"+ msg.arg1); switch(msg.what) { case EDIT_TYPE_SELECTED: ((ImageView)findViewById(msg.arg1)).setBackgroundResource(R.drawable.progress_go_small) ; break; case EDIT_TYPE_NO_SELECTED: ((ImageView)findViewById(msg.arg1)).setBackgroundResource(R.drawable.progress_bg_small) ; break; } } }; class IndexThread extends Thread { boolean flag = true; @Override public void run() { Message msg; while(flag) { for(int i= 0 ; i < count ; i++) { Log.i("Test","---"+ count); msg = new Message(); msg.what = EDIT_TYPE_SELECTED; msg.arg1 = imgIDs[i]; myHandler.sendMessage(msg); //findViewById(imgIDs[i]).setBackgroundResource(R.drawable.progress_go_small); msg = new Message(); if(i==0) { msg.what = EDIT_TYPE_NO_SELECTED; msg.arg1 = imgIDs[count-1]; myHandler.sendMessage(msg); //findViewById(imgIDs[count-1]).setBackgroundResource(R.drawable.progress_bg_small); } else { msg.what = EDIT_TYPE_NO_SELECTED; msg.arg1 = imgIDs[i-1]; myHandler.sendMessage(msg); //findViewById(imgIDs[i-1]).setBackgroundResource(R.drawable.progress_bg_small); } SystemClock.sleep(500); } } } } }XML文件如下:
<?xml version="1.0" encoding="utf-8"/?> <LinearLayout android:id="@+id/widget27" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" > <TextView android:id="@+id/widget28" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" > </TextView> <LinearLayout android:layout_width="fill_parent"android:layout_height="wrap_content" android:id="@+id/linearLayout1"> <ImageView android:id="@+id/widget29" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageView> <ImageView android:id="@+id/widget30" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageView> <ImageView android:id="@+id/widget31" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageView> <ImageView android:id="@+id/widget32" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageView> <ImageView android:id="@+id/widget33" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageView> </LinearLayout> <Button android:text="stop" android:id="@+id/button1"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout>
附件上传:
转载:http://www.adobex.com/android/source/details/00000365.htm
更多相关文章
- 记录下android studio 重命名包名
- NDK入门
- Android(安卓)studio调试smali
- Android(安卓)欢迎全屏图片详解及实例代码
- android学习之ListView如何使用
- Android开发一些常见问题
- Android(安卓)ListView侧滑删除
- Android获得当前正在显示的activity类名的方法
- ios学习笔记(5)UITabBarController用法