安卓学习-界面-布局-FrameLayout
类似于动画里的帧布局,是一层一层的
FrameLayout直接继承了ViewGroup,常用的XML属性
属性 | 方法 | 说明 |
android:foreground | setForeground(Drawable drawable) | 设置前景图像 |
android:foregroundGravity | setForegroundGravity(int foregroundGravity) | 设置前景图像的Gravity属性 |
类似荧光灯效果
1.颜色配置 colors.xml
<resources> <color name="color1">#FFC125</color> <color name="color2">#FFC1C1</color> <color name="color3">#FFD39B</color> <color name="color4">#FFF0F5</color> <color name="color5">#FFF68F</color> <color name="color6">#FFFACD</color> </resources>
2.主界面文件
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:layout_width="match_parent" android:layout_height="300dp"> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color1" /> <TextView android:id="@+id/textView2" android:layout_width="250dp" android:layout_height="250dp" android:layout_gravity="center" android:background="@color/color2" /> <TextView android:id="@+id/textView3" android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:background="@color/color3" /> <TextView android:id="@+id/textView4" android:layout_width="150dp" android:layout_height="150dp" android:layout_gravity="center" android:background="@color/color4" /> <TextView android:id="@+id/textView5" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:background="@color/color5" /> <TextView android:id="@+id/textView6" android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="center" android:background="@color/color6" /> </FrameLayout> </LinearLayout>
MainActivity.java
public class MainActivity extends Activity { private int what=132131213; private int cutColor=0; //6种颜色 private int[] colors=new int[]{ R.color.color1, R.color.color2, R.color.color3, R.color.color4, R.color.color5, R.color.color6 }; //6个textview id private int[] viewIDs=new int[]{ R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6 }; //6个textview private TextView[] views=new TextView[6]; private Handler handler=new Handler(){ public void handleMessage(android.os.Message msg) { if(msg.what==what){ for(int i=0;i<6;i++){ views[i].setBackgroundResource(colors[(i+cutColor)%5]); } cutColor=cutColor+1; Log.v("wjj",cutColor+""); } }; }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //设置views for(int i=0;i<6;i++){ views[i]=(TextView)findViewById(viewIDs[i]); } //定义一个线程,周期性改变颜色 Timer timer=new Timer(); timer.schedule(new TimerTask(){ public void run() { handler.sendEmptyMessage(what); } }, 0,200); } }