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的应用的更多相关文章

  1. Android开发之自定义组件和接口回调

    说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...

  2. Android开发之基本控件和详解四种布局方式

    Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...

  3. Android开发-之五大布局

    在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...

  4. Android开发1:基本UI界面设计——布局和组件

    前言 啦啦啦~本学期要开始学习Android开发啦~ 博主在开始学习前是完完全全的小白,只有在平时完成老师要求的实验的过程中一步一步学习~从此篇博文起,博主将开始发布Android开发有关的博文,希望 ...

  5. Android开发自学笔记(Android Studio)—4.1布局组件

    一.引言 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.在Android4.0之前,我们通常说 ...

  6. Android开发中Eclispe相关问题及相应解决(持续更新)

    1.Eclipse项目中的Android Private Libraries没有自动生成. 一般而言,在Android开发中,项目中引用到的jar包会放到项目目录中的libs中,引入库会放到Andro ...

  7. Android开发权威指南(第2版)新书发布

    <Android 开发权威指南(第二版)>是畅销书<Android开发权威指南>的升级版,内容更新超过80%,是一本全面介绍Android应用开发的专著,拥有45 章精彩内容供 ...

  8. android布局 FrameLayout(帧布局)详解

    看到一篇很有趣的文章对我就是冲着萌妹子看的 FrameLayout(帧布局) 前言 作为android六大布局中最为简单的布局之一,该布局直接在屏幕上开辟出了一块空白区域, 当我们往里面添加组件的时候 ...

  9. Xamarin Android开发实战(上册)大学霸内部资料

    Xamarin Android开发实战(上册)大学霸内部资料   试读文档下载地址:http://pan.baidu.com/s/1jGEHhhO 密码:vcfm 介绍: 本教程是国内唯一的Xamar ...

随机推荐

  1. TCP中异常关闭链接的意义 异常关闭的情况

    终止一个连接的正常方式是发送FIN. 在发送缓冲区中 所有排队数据都已发送之后才发送FIN,正常情况下没有任何数据丢失. 但我们有时也有可能发送一个RST报文段而不是F IN来中途关闭一个连接.这称为 ...

  2. Linux:宿主机通过桥接方式连接的VMware内部Linux14.04虚拟机(静态IP)实现上网方案

    首先,我们要弄清楚三种常见的连接方式中的桥接方式的网络结构: .bridged(桥接模式) 在这种模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机,它可以访问网内任何一台机器.在桥 ...

  3. 注解的基本盘点 -- 《Java编程思想》

    注解(元数据)为我们在代码中添加信息提供了一种形式化的方法,使我们可以在之后的某一个时刻非常方便地使用这些数据. ---<Java编程思想> 其实注解可以理解为一个工具类,只要使用了这个工 ...

  4. TCP/IP 协议介绍

    转自http://blog.jobbole.com/104886/ 一.TCP/IP 协议介绍 在介绍 HTTP 协议之前,先简单说一下TCP/IP协议的相关内容.TCP/IP协议是分层的,从底层至应 ...

  5. LR HTML与URL录制方式区别

    Recording录制选项 这里提供了两个大类的录制方式: 1. HTML-based script基于HTML的脚本 这种方式录制出来的脚本是基于HTML基础的,为每个用户操作生成单独的步骤,这种脚 ...

  6. CentOS 更改yum源与更新系统

    FROM:http://www.cnblogs.com/lightnear/archive/2012/10/03/2710952.html [1] 首先备份/etc/yum.repos.d/CentO ...

  7. noi 6049 买书

    题目链接: http://noi.openjudge.cn/ch0206/6049/ 6049:买书 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 小明手里有n ...

  8. linux mysql导入导出

    linux下导入.导出mysql数据库命令 一.导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径):1.导出数据和表结构:mysqldump -u用户名 -p密码 数据库名 ...

  9. Android自定义View

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 很多的Android入门程序猿来说对于Android自定义View ...

  10. kibana安装与基础用法

    来自官网,版本为4.5 下载rpm包并安装 wget -c https://download.elastic.co/kibana/kibana/kibana-4.5.4-1.x86_64.rpm rp ...