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 ...
随机推荐
- chrome浏览器不允许记忆登录账户的方法
autocomplete方法 https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_ ...
- 初识轻量级Java开源框架 --- Spring
初识轻量级Java开源框架 --- Spring 作者:egg 微博:http://weibo.com/xtfggef 出处:http://blog.csdn.net/zhangerqing spri ...
- wampserver-----------如何设置wampserver在windows下开机自动启动。
虽然很简单,但是还是做个记录.我的习惯,还是看图: 到你电脑的服务里面找到这两项然后点击右键属性,设置为自动.
- bzoj1029 [JSOI2007]建筑抢修
贪心,按截止时间排序,然后按截止时间从小到大枚举维修的建筑,如果之前修理建筑的总时间+当前修理时间<=截止时间,那么答案+1,否则如果之前修理过的建筑中最大的修理时间>当前建筑修理时间,那 ...
- session跟cookies区别
Session和Cookie的使用总结: Session和cookie都是asp.Net中的内置对象,至于他们有什么区别,在这里就不在多说,现在来说说一些比较实用点的东西: 我们知道网站都有一个后台管 ...
- Bug测试报告--连连看——天天向上
测试时间:2016-11-23 20:10 测试者:刘芳芳(nice!团队) 代码地址:HTTPS:https://git.coding.net/jx8zjs/llk.git SSH:git@git. ...
- ilbc编解码
针对国内的博客或者技术论坛对 ILBC的论述都是把文章抄来抄去, 本人在此对 ILBC的具体代码实现详细列出代码. ILBC是由Global IP Sound公司提出的一种专为包交换网络通信设计的编解 ...
- Java调用脚本
几个参考: java调用shell http://www.cnblogs.com/Seamanm/archive/2010/10/04/1842059.html java程序中调用linux命令 ...
- Moving Tables(贪心或Dp POJ1083)
Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28304 Accepted: 9446 De ...
- Java动态代理的两种实现方式:
方式一:传统的代理 package cn.hc.domain; import java.lang.reflect.InvocationHandler; import java.lang.reflect ...