【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开发中的布局很重要吗?那是当然.一切的显示样式都是由这个布局决定的,你说能不重要吗 ...
随机推荐
- python之路-模块 splinter
Splinter介绍 Splinter is an open source tool for testing web applications using Python. It lets you au ...
- SICP 习题 (1.9) 解题总结
SICP 习题 1.9 开始针对“迭代计算过程”和“递归计算过程”,有关迭代计算过程和递归计算过程的内容在书中的1.2.1节有详细讨论,要完成习题1.9,必须完全吃透1.2.1节的内容,不然的话,即使 ...
- [Immutable + AngularJS] Use Immutable .List() for Angular array
const stores = Immutable.List([ { name: 'Store42', position: { latitude: 61.45, longitude: 23.11, }, ...
- Filter简单介绍
一.简单介绍 Filter也称为过滤器,WEB开发者通过Filter技术.对webserver管理的全部web资源:比如Jsp, Servlet, 静态图片文件或静态 html 文件等进行拦截.从而实 ...
- Entity Framework数据库迁移
1.启用数据迁移: enable-Migrations2.增加一条数据库迁移指令:add-Migrations 必须带上一个版本名称,比如AddUsernamePassword完整的指令:add-Mi ...
- PHP学习笔记二十五【类的继承】
<?php //定义父类 class Stu{ public $name; protected $age; protected $grade; private $address;//私有变量不会 ...
- iOS 面试基础题
1.UIWindow和UIView和 CALayer 的联系和区别? 答:UIView是视图的基类,UIViewController是视图控制器的基类,UIResponder是表示一个可以在屏幕上响应 ...
- NSBundle 类
NSBundle NSBundle继承于NSObject,NSBundle是一个程序包,其中包含了程序会使用的资源(图像,声音,编辑好的代码,nib文件). 一. 初始化NSBundle + (ins ...
- (转+原)ipp "No dlls were found in the Waterfall procedure"
转自: http://blog.csdn.net/hua_007/article/details/9112909 1,吧 dll的目录放到系统环境变量中 intel 的官方推荐.验证是ok的. --- ...
- Linux系统的命令别名功能
命令别名功能在管理和维护Linux系统的过程中,将会使用到大量命令,有一些很长的命令或用法经常被用到,重复而频繁地输入某个很长命令或用法是不可取的.这时可以使用命令别名功能将这个过程简单化. 1.系统 ...