Android布局管理器(贞布局)
- 贞布局有FrameLayout所代表,它直接继承了ViewGroup组建
 - 贞布局为每个加入其中的组件创建一个空白区域(一帧),所以每个子组件占用一帧,这些贞都会根据gravity属性执行自动对齐
 - 贞布局在游戏开发中使用较多
 
| 
 Xml属性  | 
 相关方法  | 
 说明  | 
| 
 Android:foreground  | 
 setForeground  | 
 设置该贞的前景图形  | 
| 
 Android:foregroundGravity  | 
 SetForegroundGavity  | 
 定义绘制前景图形的gravity属性  | 
布局代码:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <TextView android:id="@+id/View01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="210dp"
android:height="50dp"
android:background="#ff0000"
/>
<TextView android:id="@+id/View02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="180dp"
android:height="50dp"
android:background="#dd0000"
/>
<TextView android:id="@+id/View03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="150dp"
android:height="50dp"
android:background="#bb0000"
/>
<TextView android:id="@+id/View04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="120dp"
android:height="50dp"
android:background="#990000"
/>
<TextView android:id="@+id/View05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="90dp"
android:height="50dp"
android:background="#770000"
/>
<TextView android:id="@+id/View06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="60dp"
android:height="50dp"
android:background="#550000"
/>
<TextView android:id="@+id/View07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="30dp"
android:height="50dp"
android:background="#330000"
/>
</FrameLayout>
Activity代码
import java.util.Timer;
import java.util.TimerTask; import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView; public class MainActivity extends Activity { private int currentColor = 0; final int[] colors = new int[]{
R.color.color7,
R.color.color6,
R.color.color5,
R.color.color4,
R.color.color3,
R.color.color2,
R.color.color1,
};
final int[] names = new int[]{
R.id.View01,
R.id.View02,
R.id.View03,
R.id.View04,
R.id.View05,
R.id.View06,
R.id.View07,
}; TextView[] views = new TextView[7]; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0 ; i<7 ;i++){
views[i] = (TextView) findViewById(names[i]);
}
//使用Handler进行获得系统消息,进行更新UI
final Handler handler = new Handler(){
public void handleMessage(Message msg) {
if(msg.what == 0x1122){
for(int i=0 ;i <7-currentColor ;i++){
views[i].setBackgroundResource(colors[i+currentColor]);
}
for(int i=7-currentColor,j=0 ; i<7 ;i++,j++){
views[i].setBackgroundResource(colors[j]);
}
}
}
};
//定义一个线程周期
new Timer().schedule(new TimerTask() { @Override
public void run() {
// TODO Auto-generated method stub
currentColor++;
if(currentColor>=6){
currentColor=0;
}
//发送一条消息通知系统
Message m = new Message();
//给该信息定义一个唯一标识
m.what = 0x1122;
handler.sendMessage(m);
}
}, 0,1000);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
效果:

Android布局管理器(贞布局)的更多相关文章
- android的布局管理器
		
理论上通过setContentView(view)能够把一个view设置到activity中,但当你有很多个view控件的时候,就需要用android的布局管理器来管理view控件了. android ...
 - android中常用的布局管理器(二)
		
接上篇博客 (3)LinearLayout 线性布局管理器 线性布局管理器是将放入其中的组件按照垂直或水平方向来布局,每一行或每一列只能放一个组件,并且不会换行,当组件排列到窗体的边缘后,后面 ...
 - 第1组UI组件:布局管理器
		
1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...
 - JAVA布局管理器
		
JAVA的界面布局原理:由于Java是跨平台语言,使用绝对坐标显然会导致问题,即在不同平台.不同分辨率下的显示效果不一样.Java 为了实现跨平台的特性并且获得动态的布局效果,Java将容器内的全部组 ...
 - 面试题-Java基础-布局管理器
		
1.什么是布局管理器? 布局管理器用来在容器中组织组件.
 - 5、Java Swing布局管理器(FlowLayout、BorderLayout、CardLayout、BoxLayout、GirdBagLayout 和 GirdLayout)
		
5.Java-Swing常用布局管理器 应用布局管理器都属于相对布局,各组件位置可随界面大小而相应改变,不变的只是其相对位置,布局管理器比较难以控制,一般只在界面大小需要改是才用,但即使这 ...
 - Java-Swing常用布局管理器
		
http://www.cnblogs.com/hthuang/p/3460234.html 5.Java-Swing常用布局管理器 应用布局管理器都属于相对布局,各组件位置可随界面大小 ...
 - Qt之布局管理器
		
简述 Qt的布局系统提供了一个简单的和强有力的方式,来自动排列窗口子控件布局. 所有QWidget子类可以使用布局来管理他们的子控件.QWidget::setLayout()函数可以为一个控件布局.当 ...
 - [置顶] Android布局管理器 - 详细解析布局实现
		
布局管理器都是以ViewGroup为基类派生出来的; 使用布局管理器可以适配不同手机屏幕的分辨率,尺寸大小; 布局管理器之间的继承关系 : 在上面的UML图中可以看出, 绝对布局 帧布局 网格布局 相 ...
 - Android布局管理器(线性布局)
		
线性布局有LinearLayout类来代表,Android的线性布局和Swing的Box有点相似(他们都会将容器里面的组件一个接一个的排列起来),LinearLayout中,使用android:ori ...
 
随机推荐
- Android中SharedPreferences和序列化结合保存对象数据
			
前言: 最近在做用户注册的时候,遇到了需要填写很多表单数据,不可能在一页把所有的数据都展示完全,因此采用了分页的方式,由于在用户填写数据数据之后我们需要对用户填写的数据进行暂时的记录的,当用户会到此页 ...
 - 一起啃PRML - 1 Introduction 绪论
			
一起啃PRML - 1 Introduction @copyright 转载请注明出处 http://www.cnblogs.com/chxer/ 这一部分主要是介绍一下Pattern Recogni ...
 - 【转】java代码中实现android背景选择的selector-StateListDrawable的应用
			
原文网址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0924/1712.html 下面的代码应该很多人都熟悉: 1 2 3 ...
 - Selenium API(C#)
			
1 Fetching a Page driver.Url = "http://www.google.com"; 2 Locating UI Elements (WebElement ...
 - MVC 5 App 通过 Facebook OAuth2 登陆(Sign-on)的问题
			
今天做了下MVC 5 App通过Google, Twitter, Linkedin 和 Facebook进行登录的例子, 算是对Asp.net Identity的一个入门,做的过程中发现了如下的问题, ...
 - 《Linear Algebra and Its Applications》-chaper4-向量空间-子空间、零空间、列空间
			
在线性代数中一个非常重要的概念就是向量空间R^n,这一章节将主要讨论向量空间的一系列性质. 一个向量空间是一些向量元素构成的非空集合V,需要满足如下公理: 向量空间V的子空间H需要满足如下三个条件: ...
 - Ural 1258 镜面对称
			
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...
 - CentOS 6.5 下安装 Redis 2.8.7(转)
			
转自:http://www.cnblogs.com/haoxinyue/p/3620648.html CentOS 6.5 下安装 Redis 2.8.7 wget http://download.r ...
 - UVA 424 (13.08.02)
			
Integer Inquiry One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...
 - svn操作
			
1.已经被svn管理的文件的复制.删除.重命名都要通过svn的命令来操作(在资源管理器中通过鼠标右键来完成)(复制粘贴可以通过右键按下移动来实现) 2.没有被svn管理的文件(没有被上传过的文件,没有 ...