android 帧布局实现跑马灯
来源:互联网 发布:好玩的桌面软件 编辑:程序博客网 时间:2024/05/30 04:25
最近在搞android开发用来一个帧布局实现了一下跑马灯的效果:
先在values文件下定一个资源文件:color.xm
<?xml version="1.0" encoding="utf-8"?><resources> <color name="color1">#FF2D2D</color> <color name="color2">#FF00FF</color> <color name="color3">#005AB5</color> <color name="color4">#28FF28</color> <color name="color5">#73BF00</color> <color name="color6">#9F4D95</color></resources>
记得要把string改为color,否则R文件将会一直保持,刚开始就是吃了这个亏
下面是布局文件:
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/view01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:width="320px" android:height="320px" android:background="#f00" /> <TextView android:id="@+id/view02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:width="280px" android:height="280px" android:background="#0f0" /> <TextView android:id="@+id/view03" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:width="240px" android:height="240px" android:background="#00f" /> <TextView android:id="@+id/view04" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:width="200px" android:height="200px" android:background="#ff0" /> <TextView android:id="@+id/view05" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:width="169px" android:height="160px" android:background="#f0f" /> <TextView android:id="@+id/view06" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:width="120px" android:height="120px" android:background="#00f" /></FrameLayout>
以下是activity的实现方法:<pre name="code" class="java">package com.zww.ui;import java.util.Timer;import java.util.TimerTask;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.Menu;import android.view.MenuItem;import android.widget.TextView;public class MainActivity2 extends Activity {private int currentColor=0;//定义一组数组的颜色final int[] colors=new int[]{R.color.color1,R.color.color2,R.color.color3,R.color.color4,R.color.color5,R.color.color6,};final int[] names=new int[]{R.id.view01,R.id.view02,R.id.view03,R.id.view04,R.id.view05,R.id.view06,};TextView[] views=new TextView[names.length];//线程监听器,传递消息Handler handler=new Handler(){@Overridepublic void handleMessage(Message msg) {if(msg.what==0x123){for(int i=0;i<names.length;i++){views[i].setBackgroundResource(colors[(i+currentColor)%names.length]);}currentColor++;}}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.frame_layout);for(int i=0;i<names.length;i++){views[i]=(TextView) findViewById(names[i]);}//定义过一个子线程周期性的改变currentColor变量值new Timer().schedule(new TimerTask(){public void run(){//发送一条空消息通知系统改变6个T组件的背景色handler.sendEmptyMessage(0X123);}},0,200);}}
0 0
- android帧布局实现跑马灯
- android 帧布局实现跑马灯
- android跑马灯实现
- android 跑马灯实现
- Android跑马灯实现
- Android跑马灯实现
- android实现跑马灯效果
- android实现跑马灯效果
- android--TextView实现跑马灯
- Android跑马灯效果实现
- android 实现跑马灯效果
- Android 跑马灯效果实现
- android实现跑马灯效果
- Android跑马灯的实现
- android跑马灯效果实现
- Android实现跑马灯效果
- Android跑马灯效果实现
- android实现跑马灯效果
- php 自制基于simple_html_dom的爬虫一只v1.0
- HTML----常用HEAD头标
- 周鸿祎对企业的深刻反思,太有借鉴意义了!
- C语言 二叉树相关
- 二维码读取与扫描
- android 帧布局实现跑马灯
- 如何修改单卡和双卡工程的默认数据连接开关
- Fireworks in Montreal
- 不注册直接使用COM组件的方法
- 杭电2014评分数组快排法和基本法
- [LeetCode]9.Palindrome Number
- javascript深入理解js闭包
- Notification用法
- If not, then the process of what would be my future