FrameLayout
<?xml version="1.0" encoding="utf-8"?> <!-- 贞布局 所有的控件将会叠加在一起,最开始添加的在最后面。 --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="320dp" android:height="320dp" android:background="#f00"> </TextView> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="280dp" android:height="280dp" android:background="#0f0"> </TextView> <TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="240dp" android:height="240dp" android:background="#00f"> </TextView> </FrameLayout>
颜色切换的“霓虹灯”
package com.frank.layoutmanage; import android.os.*; import android.app.Activity; import android.view.Menu; import android.widget.*; import java.util.Timer; import java.util.TimerTask; public class MainActivity extends Activity { private int currentColor = 0; //定义颜色数组 final int[] colors = new int[]{ R.color.color1, R.color.color2, R.color.color3 }; final int[] names = new int[]{ R.id.text1, R.id.text2, R.id.text3 }; TextView[] views = new TextView[names.length]; Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if(msg.what==0x123) { for(int i = 0;i<names.length;i++) { views[i].setBackgroundResource(colors[(i+currentColor)%names.length]); } currentColor++; } super.handleMessage(msg); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.frame_main);//指定一个布局文件 for(int i = 0;i<names.length;i++) { views[i] = (TextView)super.findViewById(names[i]); } new Timer().schedule(new TimerTask(){ @Override public void run() { //发送一条空消息通知系统 handler.sendEmptyMessage(0x123); } }, 0,200);; } @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; } }