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布局实现霓虹灯效果的更多相关文章

  1. android实例2:FrameLayout布局之霓虹灯

    个人网站http://www.ravedonut.com/ layout xml <FrameLayout xmlns:android="http://schemas.android. ...

  2. Android学习笔记:FrameLayout布局基础

    FrameLayout布局的特点是:所有放在布局里的视图组件,都按照层次堆叠在屏幕的左上角,后面的视图组件覆盖前面的. 当然,组件本身是可以控制自己的内部布局的. 一种常见的场景是可以在FrameLa ...

  3. 商城项目实战 | 1.1 Android 仿京东商城底部布局的选择效果 —— Selector 选择器的实现

    前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 京东商城的底部布局的选择效果看上去很复杂,其实很简单,这主要是要 ...

  4. Android 继承framelayout,实现ScrollView 和 HorizontalScrollView 的效果

    有些项目,需要让控件或者布局进行水平和垂直同时能拖拽,当然,ScrollView 和 HorizontalScrollView 的结合写法是一种写法.但是,这么写用户体验效果不佳,会有迟钝感,因此推荐 ...

  5. android小Demo--七彩霓虹灯效果

    七彩霓虹灯效果,基于网上的小Demo进行修改. 在android项目values文件夹下创建文件colors.xml,配置七种颜色: <?xml version="1.0" ...

  6. Android中的沉浸式状态栏效果

    无意间了解到沉浸式状态栏,感觉贼拉的高大上,于是就是试着去了解一下,就有了这篇文章.下面就来了解一下啥叫沉浸式状态栏.传统的手机状态栏是呈现出黑色条状的,有的和手机主界面有很明显的区别.这一样就在一定 ...

  7. Android组件---四大布局的属性详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4372222.html Android常见布局有下面几种: LinearL ...

  8. 14.Android之Layout布局学习

    Android布局主要有5种,接下来学习总结下. 1) 最常见的线性布局 LinearLayout 线性布局是Android布局中最简单的布局,也是最常用,最实用的布局. android:orient ...

  9. Android中的布局优化方法

    http://blog.csdn.net/rwecho/article/details/8951009 Android开发中的布局很重要吗?那是当然.一切的显示样式都是由这个布局决定的,你说能不重要吗 ...

随机推荐

  1. Dave(正方形能围成的最大点数)

    Dave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

  2. Find the maximum(规律,大数)

    Find the maximum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  3. git错误:fatal: Not a git repository (or any of the parent directories): .git

    git错误:fatal: Not a git repository (or any of the parent directories): .git 我用git add file添加文件时出现这样错误 ...

  4. javascript 之 this 用法

    参考视频:http://www.imooc.com/video/6430 JavaScript中的this比较灵活,也是让很多初学者摸不到头脑,那么根据在不同的环境下,在同一个函数,不同的调用方式下, ...

  5. document.write 存在几个问题?应该注意

    document.write (henceforth DW) does not work in XHTML XHTML 不支持 DW executed after the page has finis ...

  6. ueditor富文本编辑的使用方法

    平时在编写上传文件,图片,视频等等这些功能的代码会很繁琐,这里我介绍一款由百度推出的CuteEditor,是一款功能非常强大,支持图片上传.文件下载和word类似的文字编辑器.对于新闻发布系统和博客之 ...

  7. windows下adb(android调试桥)基本命令(持续更新。。。)

    前言:刚开始学习android(坚持每天1篇笔记哈^_^),比较实用的命令是adb,所以就先学习这些,主要用真机调试,模拟器用的是genymotion,所以emulator暂时不大需要哈,可以后续再补 ...

  8. 如何 查看 WebLogic Server的版本号[转]

    如何 查看 WebLogic Server的版本号[转] WebLogic Server 10gR3为例: 1.查看$BEA_HOME/registry.xml         => <c ...

  9. UVALive 4119 Always an integer (差分数列,模拟)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Always an integer Time Limit:3000MS     M ...

  10. Shell glob

    在Linux中,glob是用来匹配路径名的通配符,glob主要包含以下4种: Wildcard Matching * 匹配0个或者多个字符,比如d*,可以匹配d, d1, dd1 ?匹配单个字符,比如 ...