1>帧概念,在该布局内的组件,类似window编程的card层叠在一起
package com.brady.est; import java.util.Timer; import java.util.TimerTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class MainActivity extends ActionBarActivity { private int[] textViews = new int[] { R.id.view1, R.id.view2, R.id.view3, R.id.view4, R.id.view5, R.id.view6 }; private int[] colors = new int[] { R.color.color1, R.color.color2, R.color.color3, R.color.color4, R.color.color5, R.color.color6 }; private int currentImage = 0; private TextView views[] = new TextView[textViews.length]; private Handler handle = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0x444) { for (int i = textViews.length - 1; i > 0; i--) { views[i].setBackgroundResource(colors[currentImage % colors.length]); currentImage++; } } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); for (int i = 0; i < textViews.length; i++) { views[i] = (TextView) findViewById(textViews[i]); } new Timer().schedule(new TimerTask() { @Override public void run() { handle.sendEmptyMessage(0x444); } }, 0, 300); } @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); } }
FrameLayout布局文件 :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.brady.est.MainActivity" > <!-- 引入自定义组件 <com.brady.view.DrawView android:layout_width="match_parent" android:layout_height="match_parent"/> --> <TextView android:id="@+id/view1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#A32" android:layout_gravity="center" android:width="300px" android:height="300px"/> <TextView android:id="@+id/view2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#C32" android:layout_gravity="center" android:width="250px" android:height="250px"/> <TextView android:id="@+id/view3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#E32" android:layout_gravity="center" android:width="200px" android:height="200px"/> <TextView android:id="@+id/view4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#F32" android:layout_gravity="center" android:width="150px" android:height="150px"/> <TextView android:id="@+id/view5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#B32" android:layout_gravity="center" android:width="100px" android:height="100px"/> <TextView android:id="@+id/view6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#C32" android:layout_gravity="center" android:width="50px" android:height="50px"/> </FrameLayout>
颜色资源Xml文件:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="color1" translatable="false">#0f0</color> <color name="color2" translatable="false">#f00</color> <color name="color3" translatable="false">#00f</color> <color name="color4" translatable="false">#0c0</color> <color name="color5" translatable="false">#c00</color> <color name="color6" translatable="false">#00c</color> </resources>
时间: 2024-10-07 23:38:52