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 ...
随机推荐
- HTML 中按钮作为form表单元素提交特性两则 --- 参HTML考标准分析
相同name的submit 类型的input提交行为 描述 这种情况, <input type="submit" name="ACTION" value= ...
- lua 模块功能
lua5.1 模块理解 http://www.lua.org/manual/5.1/manual.html#pdf-module 模块 5.3 – Modules The package librar ...
- Java Servlet(六):HttpServlet实现原理(jdk7+tomcat7+eclipse)
本篇记录了HttpServlet的实现过程,主要讲述了如何依赖Servlet,GenericServlet实现的原理. HttpServlet实现过程:1.是一个Servlet,继承自GenericS ...
- ECMAScript数据类型
[ 基本数据类型 ]-->5种 Undefined Null Boolean Number String [ 复杂数据类型 ]-->1种 Object [ typeof 返回值] --&g ...
- 【NFC】Android NFC API Reference中英文
0 Near Field Communication Near Field Communication (NFC) is a set of short-range wireless technol ...
- 【转】ACM/ICPC生涯总结暨退役宣言—alpc55
转自:http://hi.baidu.com/accplaystation/item/ca4c2ec565fa0b7fced4f811 ACM/ICPC生涯总结暨退役宣言—alpc55 前言 早就该写 ...
- Ruby(Selenium / Rspec)在Windows 8_64上安装步骤
1.首先需要下载RubyInstaller.exe程序(下载地址随便都能找到). 如:rubyinstaller-2.2.2-x64.exe 安装好Ruby后,需要更新Gems gem update ...
- sqlyong64位破解
姓名(Name):cr173 序列号(Code):8d8120df-a5c3-4989-8f47-5afc79c56e7c 或者(OR) 姓名(Name):cr173 序列号(Code):59adfd ...
- Case1:WorkFlow不能运行的解决办法
原因为CRMAppPool选择了一个域用户,然后异步服务的用户执行会有问题 at CrmException..ctor(Int32 errorCode, Object[] arguments) ilO ...
- datagridview随窗体的大小而变,表格填满控件
在C#winform布局的时候,我们拖一个datagridview到窗体上面,将datagridview调整为适合窗体的大小,但是我们运行之后,点击最大化按钮的时候,却发现datagridview的大 ...