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 ...
随机推荐
- Delphi消息的广播方式(先RegisterWindowMessage,后SendMessage HWND_BROADCAST,最后改写接收窗口的WndProc)
///////消息广播只能将消息传递到接收消息的主程序中,MDIChild窗体不能接收到广播消息:///////// unit Unit1; interface uses Windows, Messa ...
- 纯CSS打造可折叠树状菜单
1:Html代码 <li> <label for="subsubfolder1">下级</label> <input id="s ...
- 【HDOJ】前三百留念
4个月不到的时间,终于刷到了HDOJ前三百.肯定还不够,好多基本的算法还不了解.还得继续学习.以此留念,假期目标是前一百.
- XCode4 下制作Framework的方法
http://www.cocoachina.com/bbs/read.php?tid-75680-page-1.html
- 详解集群内Session高可用的实现原理
在这个互联网高度发达的时代,许多应用的用户动辄成百上千万,甚至上亿.为了支持海量用户的访问,应用服务器集群这种水平扩展的方式是最常用的.这种情形下,就会涉及到许多单机环境下完全不需要考虑的问题,这其中 ...
- weekend110(Hadoop)的 第六天笔记
(2015年1月25日) 课程目录 01-复习ha相关 02-hive的元数据库mysql方式安装配置 03-hive的使用 04-hive的常用语法 05-hql语法及自定义函数 06-hbase表 ...
- Install MongoDB on Windows (Windows下安装MongoDB)
Install MongoDB on Windows Overview Use this tutorial to install MongoDB on a Windows systems. PLATF ...
- windows Nginx基本使用方法
相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人未必了解. 说到反向代理,可能很多人都听说,但具体什么是反向代理,很多人估计就不清楚了 ...
- Linux的定时任务
分两种:一次性的定时任务.周期性的定时任务. 一次性的定时任务,又称at定时任务,命令为atd ,这里d是deamon的首字母,守护的意思,指守护进程:其实很多程序都是以d结尾,如httpd.memc ...
- iOS开发总结-UIWebView 集成 浏览器
// // detailWebViewController.m // BJ // // Created by shirenfeng on 16/11/6. // Copyright © 2016年 c ...