1. 贞布局有FrameLayout所代表,它直接继承了ViewGroup组建
  2. 贞布局为每个加入其中的组件创建一个空白区域(一帧),所以每个子组件占用一帧,这些贞都会根据gravity属性执行自动对齐
  3. 贞布局在游戏开发中使用较多

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布局管理器(贞布局)的更多相关文章

  1. android的布局管理器

    理论上通过setContentView(view)能够把一个view设置到activity中,但当你有很多个view控件的时候,就需要用android的布局管理器来管理view控件了. android ...

  2. android中常用的布局管理器(二)

    接上篇博客 (3)LinearLayout     线性布局管理器 线性布局管理器是将放入其中的组件按照垂直或水平方向来布局,每一行或每一列只能放一个组件,并且不会换行,当组件排列到窗体的边缘后,后面 ...

  3. 第1组UI组件:布局管理器

    1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...

  4. JAVA布局管理器

    JAVA的界面布局原理:由于Java是跨平台语言,使用绝对坐标显然会导致问题,即在不同平台.不同分辨率下的显示效果不一样.Java 为了实现跨平台的特性并且获得动态的布局效果,Java将容器内的全部组 ...

  5. 面试题-Java基础-布局管理器

    1.什么是布局管理器? 布局管理器用来在容器中组织组件.

  6. 5、Java Swing布局管理器(FlowLayout、BorderLayout、CardLayout、BoxLayout、GirdBagLayout 和 GirdLayout)

    5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小而相应改变,不变的只是其相对位置,布局管理器比较难以控制,一般只在界面大小需要改是才用,但即使这 ...

  7. Java-Swing常用布局管理器

    http://www.cnblogs.com/hthuang/p/3460234.html   5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小 ...

  8. Qt之布局管理器

    简述 Qt的布局系统提供了一个简单的和强有力的方式,来自动排列窗口子控件布局. 所有QWidget子类可以使用布局来管理他们的子控件.QWidget::setLayout()函数可以为一个控件布局.当 ...

  9. [置顶] Android布局管理器 - 详细解析布局实现

    布局管理器都是以ViewGroup为基类派生出来的; 使用布局管理器可以适配不同手机屏幕的分辨率,尺寸大小; 布局管理器之间的继承关系 : 在上面的UML图中可以看出, 绝对布局 帧布局 网格布局 相 ...

  10. Android布局管理器(线性布局)

    线性布局有LinearLayout类来代表,Android的线性布局和Swing的Box有点相似(他们都会将容器里面的组件一个接一个的排列起来),LinearLayout中,使用android:ori ...

随机推荐

  1. Hibernate之SchemaExport+配置文件生成表结构

    首先要生成表,得先有实体类,以Person.java为例: /** * * @author Administrator * @hibernate.class table="T_Person& ...

  2. Extjs4开发中的一些问题

    1.  子frame刷新的问题 一般在jsp里面,要实现界面跳转,有很多方法,最典型的就是window.location.href="href",但是在嵌套有iframe框架的页面 ...

  3. Delphi 6 Web Services初步评估之三(转)

    Delphi 6 Web Services初步评估之三(转)   Delphi 6 Web Services初步评估之三(转)★ 测试总体印象:在整个测试中,对Delphi 6创建的Web Servi ...

  4. HDU-4972 A simple dynamic programming problem

    http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming proble ...

  5. maya绝招(1-20)

    第一招 自制MAYA启动界面 在安装目录下的BIN文件夹中的MayaRes.dll文件,用Resource Hacker打开.在软件的目录树中找到“位图”下的MAYASTARTUPIMAGE.XPM并 ...

  6. 新手入门 acm 输入输出练习

    A + B Problem(1000) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. vijosP1195“非常男女”计划

    vijosP1195“非常男女”计划 链接:https://vijos.org/p/1195 [思路] 人数差. 人数差相等的两点之间的区间一定有男女人数相等. 计目前为止到i的1为sum1,0为su ...

  8. XML文档部署到Tomcat服务器上总是加载出错

    config.xnl 起初文档路径是在src/Dao/config.xml 在Dao目录下BaseDao类中,解析config.xml文件路径 path="/Dao/config.xml&q ...

  9. win7不能在同一窗口打开文件夹,解决办法

    1.由于IE浏览器的主页被劫持,总是忽然弹出搜狗的主页,有的时候,忽然弹出IE浏览器(主页是搜狗),然后又自行关闭,我X,我的电脑竟然不受我控制,这可得了,这里我又要骂宁美国度了,made,组装机装了 ...

  10. jersey 过滤器

    这里使用的Jersey 是 1.1 版本 1.  web.xml 配置 <?xml version="1.0" encoding="UTF-8"?> ...