【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开发中的布局很重要吗?那是当然.一切的显示样式都是由这个布局决定的,你说能不重要吗 ...
随机推荐
- 89c52串口发送接收小示例
//串口发送 void sendChar(char *p)//调用前关中断,调用完成后关中断 { while(*p != '\0') { SBUF = *P while(!TI); TI = 0; p ...
- css之浏览器初始化方案
HTML, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote,pre, form, fieldset, ...
- SQL按汉语拼音首字母排序
以常用到的省的数据表(province)为例,其中name字段为省的名称,SQL语句如下: ))) as py ,a.name from province a left outer join ( se ...
- C# List<T>的详细用法
所属命名空间:System.Collections.Generic List<T>类是 ArrayList 类的泛型等效类.该类使用大小可按需动态增加的数组实现 IList<T> ...
- jQuery源码学习:使用隐藏的new来创建对象
在JQuery源码中发现,JQuery定义一个类,但不用new关键字去创建该类对象,而使用方法调用()方式去创建该对象. 很多时候我们是这样写类,然后使用new创建对象的: function Pers ...
- debian修改系统语言为英文
原文地址:http://www.chenyudong.com/archives/debian-change-locale-language.html 修改/etc/default/locale 文件里 ...
- python 多线程、多进程
一.首先说下多线程.多进程用途及异同点,另外还涉及到队列的,memcache.redis的操作等: 1.在python中,如果一个程序是IO密集的操作,使用多线程:运算密集的操作使用多进程. 但是,其 ...
- shell脚本练习(短路练习)
#!/bin/bash #By Spinestars#2013-11-11#This is a lvsnap of auto-create Help(){ echo "Usage: ---d ...
- IIS6.0架构概览(翻译)
IIS6.0提供一个重新设计的万维网发布服务(World Wide Web Publishing Service)架构,可以帮助你为你的网站构建更好的性能.可靠.可扩展性(scalability),无 ...
- H5+Boostrap的音乐播放器
H5+Boostrap做简单的音乐播放器 前言:这个是综合一下我最近在学的东西做的小Demo,到实际使用还有距离,但是用来练手巩固知识点还是不错的,最近在二刷JS书和Boostrap.css的源码,做 ...