【Android】使用FrameLayout布局实现霓虹灯效果
FrameLayout是五大布局中最简单的一个布局。
在这个布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置。
它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。
显示效果如下,第一个TextView被第二个TextView完全遮挡,第三个TextView遮挡了第二个TextView的部分位置。
我们可以利用这个FrameLayout布局的特性实现一个简单的霓虹灯效果。
Activity代码
package com.app.test01; import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View; public class FrameLayoutActivity extends Activity implements Runnable{
//定义5个颜色值
private int[] colors = new int[]{0xFFFF0000,0xFF0000FF,0xFF00FFFF,0xFFFF00FF,0xFF00FF00};
//每一个颜色值的索引
private int[] nextColorPoints = new int[]{1,2,3,4,0};
//当前值的索引
private int currentColorPoint = 0;
private View[] views;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame);
views = new View[]{findViewById(R.id.textView5),findViewById(R.id.textView4),
findViewById(R.id.textView3),findViewById(R.id.textView2),findViewById(R.id.textView1)};
handler = new Handler();
handler.postDelayed(this, 300);
} @Override
public void run() {
// TODO Auto-generated method stub
int nextColorPoint = currentColorPoint;
for (int i = views.length-1; i>=0; i--) {
views[i].setBackgroundColor(colors[nextColorPoint]);
nextColorPoint = nextColorPoints[nextColorPoint];
}
currentColorPoint++;
if (currentColorPoint == 5) {
currentColorPoint = 0;
}
handler.postDelayed(this, 300);
}
}
布局文件
<?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/textView1"
android:layout_width="300dp"
android:layout_height="300dp"
android:text="TextView"
android:layout_gravity="center"/> <TextView
android:id="@+id/textView2"
android:layout_width="240dp"
android:layout_height="240dp"
android:text="TextView"
android:layout_gravity="center"/> <TextView
android:id="@+id/textView3"
android:layout_width="180dp"
android:layout_height="180dp"
android:text="TextView"
android:layout_gravity="center"/> <TextView
android:id="@+id/textView4"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="TextView"
android:layout_gravity="center"/> <TextView
android:id="@+id/textView5"
android:layout_width="60dp"
android:layout_height="60dp"
android:text="TextView"
android:layout_gravity="center"/> </FrameLayout>
效果图
【Android】使用FrameLayout布局实现霓虹灯效果的更多相关文章
- android实例2:FrameLayout布局之霓虹灯
个人网站http://www.ravedonut.com/ layout xml <FrameLayout xmlns:android="http://schemas.android. ...
- Android学习笔记:FrameLayout布局基础
FrameLayout布局的特点是:所有放在布局里的视图组件,都按照层次堆叠在屏幕的左上角,后面的视图组件覆盖前面的. 当然,组件本身是可以控制自己的内部布局的. 一种常见的场景是可以在FrameLa ...
- 商城项目实战 | 1.1 Android 仿京东商城底部布局的选择效果 —— Selector 选择器的实现
前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 京东商城的底部布局的选择效果看上去很复杂,其实很简单,这主要是要 ...
- Android 继承framelayout,实现ScrollView 和 HorizontalScrollView 的效果
有些项目,需要让控件或者布局进行水平和垂直同时能拖拽,当然,ScrollView 和 HorizontalScrollView 的结合写法是一种写法.但是,这么写用户体验效果不佳,会有迟钝感,因此推荐 ...
- android小Demo--七彩霓虹灯效果
七彩霓虹灯效果,基于网上的小Demo进行修改. 在android项目values文件夹下创建文件colors.xml,配置七种颜色: <?xml version="1.0" ...
- Android中的沉浸式状态栏效果
无意间了解到沉浸式状态栏,感觉贼拉的高大上,于是就是试着去了解一下,就有了这篇文章.下面就来了解一下啥叫沉浸式状态栏.传统的手机状态栏是呈现出黑色条状的,有的和手机主界面有很明显的区别.这一样就在一定 ...
- Android组件---四大布局的属性详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4372222.html Android常见布局有下面几种: LinearL ...
- 14.Android之Layout布局学习
Android布局主要有5种,接下来学习总结下. 1) 最常见的线性布局 LinearLayout 线性布局是Android布局中最简单的布局,也是最常用,最实用的布局. android:orient ...
- Android中的布局优化方法
http://blog.csdn.net/rwecho/article/details/8951009 Android开发中的布局很重要吗?那是当然.一切的显示样式都是由这个布局决定的,你说能不重要吗 ...
随机推荐
- 黑马程序员 Java正则表达式,详解反斜线在Java中的作用
---------------------- ASP.Net+Android+IO开发S. .Net培训.期待与您交流! ---------------------- 在程序设计过程中,经常需要对获取 ...
- Linux正則表達式-反复出现的字符
星号(*)元字符表示它前面的正則表達式能够出现零次或多次.也就是说,假设它改动了单个字符.那么该字符能够在那里也能够不在那里,而且假设它在那里,那可能会不止出现一个.能够使用星号元字符匹配出如今引號中 ...
- 机房收费系统合作版(三)——UI思索
案件追踪系统1.0暂告一段落.验收过程中.MR MI针对UI界面提出了很多自己的想法. 针对TGB项目的UI设计我也有我的感受: 1.不论大小项目.仅仅要一看界面准有70%到80%熟悉度. 2.一看这 ...
- hdu1171 Big Event in HDU 01-背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...
- Oracle:grouping和rollup
Oracle grouping和rollup简单测试 SQL,,,) group by department_id order by department_id; DEPARTMENT_ID SUM( ...
- Centos 7 python升级(2.7.5-》2.7.11)
1.安装升级GCC yum install gcc* openssl openssl-devel ncurses-devel.x86_64 bzip2-devel sqlite-devel pyth ...
- 解决数据库Operation not allowed when innodb_forced_recovery > 0
解决数据库Operation not allowed when innodb_forced_recovery > 0 请修改my.cnf innodb_force_recovery = 1 修改 ...
- .net中用到的一些方法
//文件操作string fullDirPath = Utils.GetMapPath(string.Format("/aspx/{0}/", buildPath)); Direc ...
- AngularJS Directive - 开场小介绍(转)
Directive其实就是让html变得更强大的一种方法.它可以根据需求对dom变形,或注入行为. 觉得它很神秘么,其实一点儿也不神秘,只要开始使用AngularJS了,就一定在使用着Directiv ...
- SQL按汉语拼音首字母排序
以常用到的省的数据表(province)为例,其中name字段为省的名称,SQL语句如下: ))) as py ,a.name from province a left outer join ( se ...