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 ...
随机推荐
- CentOS-6 yum安装nginx php53 mysql55 搭建LNMP环境
1.导入外部软件库 01.rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noa ...
- MVC 的各个部分都有那些技术来实现?如何实现?
MVC 的各个部分都有那些技术来实现?如何实现? MVC 是 Model-View-Controller 的简写 "Model" 代表的是应用的业务逻辑(通过JavaBean,EJ ...
- HDU 1176 免费馅饼
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- MVC网址路由与生命周期
这篇写得比较详细,所以我收藏一下. 转载自: http://www.cnblogs.com/Eleanore/archive/2012/11/23/2783061.html 一.网址路由 1.1 比 ...
- IUS
后端提取的sdf中可能是有negative timing 在interconnect上的,可能的原因是crosstalk之类的问题导致. negative timing在FF,clock的delay超 ...
- zTree插件之多选下拉菜单代码
zTree插件之多选下拉菜单代码 css和js <!--ztree树结构--> <link rel="stylesheet" type="text/cs ...
- Magento 自定义一个搜索功能
最近工作中有一个需求是需要做一个搜索的功能,但是因为需要定制一些外观,所以就不用传统的方法来继承基类GRID.实现这个需求的核心其实就是下面这个方法. $this->getLayout()-&g ...
- html5,表单
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- [Effective JavaScript 笔记]第68条:使用promise模式清洁异步逻辑
构建异步API的一种流行的替代方式是使用promise(有时也被称为deferred或future)模式.已经在本章讨论过的异步API使用回调函数作为参数. downloadAsync('file.t ...
- 解决连接VPN后无法上网问题
解决连接VPN后无法上网问题 VPN的英文全称是“Virtual Private Network”,翻译过来就是“虚拟专用网络”.顾名思义,虚拟专用网络可以把它理解成是虚拟出来的企业内部专线. 在公司 ...