Android开发--FrameLayout的应用
1.简介
frameLayout为框架布局,该布局的特点为层层覆盖,即最先放置的部件位于最下层,最后放置的部件位于最上层。
2.构建
如图所示,该视图中有五个TextView。其中,tv1放置在最底层,tv5放置在外层,即tv5将遮掩tv1的部分内容。
我们让五个TextView不断变换颜色,形成霓虹灯的效果。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="example.framelayout.Activity1" >
<TextView
android:id="@+id/textView1"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:text="@string/tv1" />
<TextView
android:id="@+id/textView2"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_gravity="center"
android:text="@string/tv2" />
<TextView
android:id="@+id/textView3"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_gravity="center"
android:text="@string/tv3" />
<TextView
android:id="@+id/textView4"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:text="@string/tv4" />
<TextView
android:id="@+id/textView5"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:text="@string/tv5" />
</FrameLayout>
3.代码
public class Activity1 extends Activity implements Runnable{
//定义五种颜色
private int colors[]=new int[]{0xFF6495ED,0xFFEE82EE,0xFFFF69B4,0xFF6495ED,0xFF0000FF};
//为每一种颜色定义索引
private int nextcolor[]= new int[] {1,2,3,4,0};
//定义当前颜色值的索引
private int currentcolor=0;
//handler
private Handler handler;
//声明五个TextView
private View views[];
@Override
public void run() {
int indexcolor=currentcolor;
for(int i=views.length-1;i>=0;i--){
views[i].setBackgroundColor(colors[nextcolor[indexcolor]]);
indexcolor=nextcolor[indexcolor];
}
//为TextView的下一颜色做准备,indexcolor将为1,此时所有TextView将出现不同鱼第一次的颜色。
currentcolor++;
//由于数组长度为5,为防止数组越界,即出现nextcolor[5]的情况,需要让currentcolor重新开始。
if(currentcolor==5)
currentcolor=0;
//启动handler,延时300ms
handler.postDelayed(this, 300);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.act1);
//将TextView与ID匹配
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,延时300ms
handler.postDelayed(this, 300);
}
3.展示
Android开发--FrameLayout的应用的更多相关文章
- Android开发之自定义组件和接口回调
说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...
- Android开发之基本控件和详解四种布局方式
Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...
- Android开发-之五大布局
在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...
- Android开发1:基本UI界面设计——布局和组件
前言 啦啦啦~本学期要开始学习Android开发啦~ 博主在开始学习前是完完全全的小白,只有在平时完成老师要求的实验的过程中一步一步学习~从此篇博文起,博主将开始发布Android开发有关的博文,希望 ...
- Android开发自学笔记(Android Studio)—4.1布局组件
一.引言 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.在Android4.0之前,我们通常说 ...
- Android开发中Eclispe相关问题及相应解决(持续更新)
1.Eclipse项目中的Android Private Libraries没有自动生成. 一般而言,在Android开发中,项目中引用到的jar包会放到项目目录中的libs中,引入库会放到Andro ...
- Android开发权威指南(第2版)新书发布
<Android 开发权威指南(第二版)>是畅销书<Android开发权威指南>的升级版,内容更新超过80%,是一本全面介绍Android应用开发的专著,拥有45 章精彩内容供 ...
- android布局 FrameLayout(帧布局)详解
看到一篇很有趣的文章对我就是冲着萌妹子看的 FrameLayout(帧布局) 前言 作为android六大布局中最为简单的布局之一,该布局直接在屏幕上开辟出了一块空白区域, 当我们往里面添加组件的时候 ...
- Xamarin Android开发实战(上册)大学霸内部资料
Xamarin Android开发实战(上册)大学霸内部资料 试读文档下载地址:http://pan.baidu.com/s/1jGEHhhO 密码:vcfm 介绍: 本教程是国内唯一的Xamar ...
随机推荐
- SecureCRT工具配色方案
一.配色后的效果图 二.设置背景颜色 1.选项(Options)==>会话选项(Sessions options)==>终端(Terminal)==>仿真(Emulation) 2. ...
- Apache和IIS服务器共存问题--来自网上内容
1.apache 主要支持PHP IIS 主要支持asp 静态的网页他们都支持入htm,端口冲突的话你可以更改其中一个服务器的端口来实现端口的避让,IIS在右击“我的电脑”“管理”“服务和应用程 ...
- sql server 中删除表中数据truncate和delete的区别(转载自.net学习网)
我们都知道truncate table可以用来删除整个表的内容,它与delete后面不跟where条件的效果是一样.但除此之外,我们还清楚它们之间有其它的区别吗?本章我们将一起讨论truncate与d ...
- Redis缓存之Set使用
在Redis中,我们可以将Set类型看作为没有排序的字符集合,和List类型一样,我们也可以在该类型的数据值上执行添加.删除或判断某一元素是否存在等操作.需要说明的是,这些操作的时间复杂度为O(1), ...
- 刨根问底U3D---如何退出Play模式后保留数据更改
实际中遇到的需求 在做一款对抗类游戏,目前正在调整游戏的平衡性 所以就产生了一个需求 希望可以在Play模式时候对数据源做的更改可以在退出时候被保存下来. 举个Case, 比如 有一个炮塔 可以发射子 ...
- 关于为busybox设置setuid
安卓root了,重启之后就没root权限了,于是想到了为 busybox 设置 setuid 来实现使用root的身份执行命令. 可是,不管用啊,还是提示没有权限.搜了一下 busybox setui ...
- 【转】PowerShell入门(八):函数、脚本、作用域
转至:http://www.cnblogs.com/ceachy/archive/2013/02/26/PoweShell_Function_Script_Scope.html 脚本所体现的是Powe ...
- 简单破解.net(C#)程序
一直在用makedown2(free版),每当打开多个页面,就会提示升级为pro,还要注册码激活什么的.就有了破解的想法.以前也弄过一个小程序的破解,所以还算有些经验. 1. ildasm 用来将ma ...
- Create Your Tab and LayerTabMenu In Katana
感谢 http://tool.lu/pyc/ 这个牛逼的网站能反编译pyc...他妈的Katana太他妈无耻了,竟然不让自定义加Node Tab Content....只能反编译他的东西了... 研究 ...
- js加密的密文让PHP解密(AES算法)
JS加密代码如下 <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/aes ...