java多线程霓虹灯,Android开发实现布局帧布局霓虹灯效果示例
本文实例讲述了Android开发实现布局帧布局霓虹灯效果。分享给大家供大家参考,具体如下:
效果图:
实现方式:
FrameLayout中,设置8个TextView,在主函数中,设计颜色数组,通过有序替换他们颜色,实现渐变效果。
java代码:MainActivity
public class MainActivity extends AppCompatActivity {
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,
R.color.color7,
R.color.color8
};
final int[] names= new int[]{
R.id.view01,
R.id.view02,
R.id.view03,
R.id.view04,
R.id.view05,
R.id.view06,
R.id.view07,
R.id.view08
};
TextView[] views = new TextView[names.length];
Handler handler = new Handler(){
@Override
public 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++;
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i < names.length; i++){//更换颜色
views[i] = (TextView) findViewById(names[i]);
}
//定义一个线程改变current变量值
new Timer().schedule(new TimerTask() {
@Override
public void run() {
//发送一条空消息通知系统改变6个TextView颜色
handler.sendEmptyMessage(0x123);
}
}, 0, 300);
}
}
xml文件
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/view01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="320dp"
android:height="320dp"
android:background="#ea7500"/>
android:id="@+id/view02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="280dp"
android:height="280dp"
android:background="#ff8000"/>
android:id="@+id/view03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="240dp"
android:height="240dp"
android:background="#ff9224"/>
android:id="@+id/view04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="200dp"
android:height="200dp"
android:background="#ffa042"/>
android:id="@+id/view05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="160dp"
android:height="160dp"
android:background="#ffaf60"/>
android:id="@+id/view06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="120dp"
android:height="120dp"
android:background="#ffa042"/>
android:id="@+id/view07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="80dp"
android:height="80dp"
android:background="#ff9224"/>
android:id="@+id/view08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="40dp"
android:height="40dp"
android:background="#ff8000"/>
color资源文件设置:
#008577
#00574B
#D81B60
#844200
#d26900
#ff9224
#ffbb77
#ffd1a4
#ffaf60
#ff8000
#bb5e00
希望本文所述对大家Android程序设计有所帮助。
java多线程霓虹灯,Android开发实现布局帧布局霓虹灯效果示例相关推荐
- android 小球效果,Android开发实现跟随手指的小球效果示例
本文实例讲述了android开发实现跟随手指的小球效果.分享给大家供大家参考,具体如下: 配置drawview类用于绘制小球 public class drawview extends view { ...
- android中帧布局效果,Android开发实现布局帧布局霓虹灯效果示例
本文实例讲述了android开发实现布局帧布局霓虹灯效果.分享给大家供大家参考,具体如下: 效果图: 实现方式: framelayout中,设置8个textview,在主函数中,设计颜色数组,通过有序 ...
- android开发基础1-界面布局(明日科技教程)
用户界面设计 View view:可以理解为视图,占据屏幕上的一块矩形区域,负责提供组建绘制和事件处理的方法 如果把android界面比喻成一个窗口,则每个view都是一块玻璃.一般是使用view类的 ...
- 是否可以将Java 8用于Android开发?
本文翻译自:Is it possible to use Java 8 for Android development? Searching the web, it is not clear if Ja ...
- android开发 RecyclerView 瀑布列表布局
android开发 RecyclerView 瀑布列表布局 1.写一个内容的自定义小布局: <?xml version="1.0" encoding="utf-8& ...
- Android开发第二次课 布局方式
线性布局 线性布局: 控件从左到右排列:水平方式 控件从上到下排列:垂直方式 标签:LinearLayout <LinearLayoutxmlns:android="http://sc ...
- android 继承relativelayout,Android开发中RelativeLayout相对布局
Android开发中RelativeLayout相对布局 RelativeLayout布局是Android界面布局中应用最广也最强大的一种布局,其不只十分灵活,能够解决开发中各类界面布局需求,同时也很 ...
- android简单实现表格布局,Android开发中TableLayout表格布局
Android开发中TableLayout表格布局 一.引言 在移动端应用程序开发中,常常会使用到表格布局,iOS和Android开发框架中都提供了独立的表格视图控件供开发者使用,例如iOS中的UIT ...
- android动画送礼物,Android开发仿映客送礼物效果
这里写链接内容仿映客送小礼物的特效,顺便复习一下属性动画,话不多说先看效果图. 需求分析 可以看到整个动画有几部分组成,那我们就把每个部分拆分出来各个击破. 1.要显示那些内容以及内容间的位置关系? ...
最新文章
- mysql5.7 zip安装配置_MySQL5.7的.zip文件的配置安装
- python测试开发django-1.开始hello world!
- HtmlTextWriter学习
- spring事务介绍 1
- 5G第一个演进版本标准完成 3GPP宣布R16标准冻结
- angular学习笔记(九)-css类和样式2
- Pulseaudio之同步/异步(十一)
- php 查询逗号分隔字符串,PHP-在逗号分隔的字符串mysql中查找值
- stm32实现串口通信和LED灯点亮
- web网页设计期末课程大作业 基于HTML+CSS+JavaScript响应式环保科技公司网站模板(环保主题网站设计)
- / ./ ../相对路径详细解释
- 你能发现什么?又能坚持什么?
- 【HDOJ】3505 Writing Robot
- 前端实现 导出图片,导出PDF(截图原理)
- 2款 新版月老在线牵盲盒+交友盲盒+小纸条盲盒+交友匹配+同城交友小程序源学习
- 数组的降维与升维方法
- 刘莹:提升站内搜索的五大必要性
- ARTS-9(幸福的奥秘是什么?)
- mac 安装python并切换到python3版本
- 网站使用新浪微博登录