UI复习-布局管理器FrameLayout(霓虹灯)

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-08-05 01:33:52

UI复习-布局管理器FrameLayout(霓虹灯)的相关文章

UI复习-布局管理器GridLayout(计算器界面)

1>GridLayout,4.0版本以上新增的网格布局,以下版本需要引用支撑包 package com.brady.est; import android.annotation.SuppressLint; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.Gravity; import android.view.Menu; import android.vi

安卓开发:UI组件-布局管理器和文本显示

接下来的随笔,记录了在学习b站up主:天哥在奔跑,录制的教学视频的同时,进行一个app开发. up主:天哥在奔跑 视频地址:https://www.bilibili.com/video/av38409964?from=search&seid=1641333322970886700 开发app:师傅网 2.1布局管理器 每个界面上元素有很多,各元素相互之间的摆放位置与元素关系,就由布局管理器完成.常用的两种布局为线性布局(LinearLayout)和相对布局(RelativeLayout). 2.

android中常用的布局管理器

Android中的几种常用的布局,主要介绍内容有: View视图 RelativeLayout    相对布局管理器 LinearLayout     线性布局管理器 FrameLayout     真布局管理器 TableLayout     表格布局管理器 GridLayout     网格布局管理器 (1) View在XML文件中的常用属性定义: layout_margin:指定该视图与周围视图之间的空白距离(包括上下左右),(可分别写成layout_marginTop.layout_ma

Android第二节(view简介以及Android布局管理器),维维复习

布局管理器是指定View之间的排列方式的.view就是UI控件,下节课我会整理到,这里我们先讲布局,大布局在我看来就相当于一个房间,让view显示,就是说物品在房间的摆放规则. 一.View的简介 View ,一般都有TextView,EditText,Button,RadioButton,CheckBox,ImageView,ImageButton. ViewGroup,一般有LinearLayout,RelativeLayout,FrameLayout,Spinner,ListView,Gr

Android【布局管理器语法】之四大布局【LinearLayout,TableLayout,FrameLayout,RelativeLayout】

LinearLayout 线性布局是将放入其中的组件按照垂直(vertical)或者水平(horizontal)方向来布局, 也就是控制其中组件横向排列或者纵向排列.在线性布局中 每一行[针对垂直排列]或每一列[针对水平排列]只能放一个组件 . 注意:Android线性布局不会换行,当组件一个挨着一个排列到窗体边缘后 剩下的组件将不会显示出来 排列方式由android:orientation属性控制,对齐方式由android:gravity属性来控制 (1)常见属性: android:orien

布局管理器

线性布局 线性布局由LinearLayout类来代表.可以控制组件横向排列和纵向排列. 注:android:gravity属性中的多个属性值之间用竖线隔开,但竖线前后千万不能出现空格. 表格布局 表格布局由TableLayout所代表,表格布局采用行.列的形式来管理UI组件,TableLayout并不需要明确地声明包含多少行.多少列,而是通过添加TableRow.其他组件来控制表格的行数和列数. 每次向TableLayout中添加一个TableRow,该TableRow就是一个表格行,Table

Android布局管理器浅析

在Android应用开发中,为了更好地管理Android应用的用户界面里的各组件,Android提供了布局管理器来实现Android应用的图形用户界面平台无关性,其中所有布局管理器的父类为ViewGroup.一般来说,推荐使用布局管理器来管理组件的分布.大小,而不是直接设置组件位置和大小.在开发当中,最常用的方法是预先设置好容器边距(分布).大小,然后其包含的组件使用"fill_match"或"wrap_content"自动适应父容器即可. 一.LinearLayo

android v7兼容包RecyclerView的使用(三)——布局管理器的使用

前两篇文章 android v7兼容包RecyclerView的使用(二) android v7兼容包RecyclerView的使用(一) 介绍了RecyclerView的基本用法以及与它相关的重要的几个类,本篇文章介绍布局管理器的具体用法. 为了演示布局管理器的使用,找了很多个例子,都没有找到感觉合适的例子,后来google了一把,发现了一个比较适合说明问题的例子.所以就拿该例子来解释吧. 在演示布局管理器前,我们先把UI部分搭建完成.由于使用到了V7兼容包的另一个包CardView,所以在这

2.2UI组件(一)布局管理器

所有的布局管理器都是ViewGroup的子类. 2.2.1线性布局LinearLayout android:orientation:可以控制竖排显示(vertical)或者横排显示(horizontal) LInearLayout不会自动换行,一旦屏幕排满之后后面的控件将看不到 基本上很多布局管理器都提供了相应的LayoutParams内部类,该内部类用于控制他们的子元素使他们都具有android:layout_gravity属性,概述性设置子元素在父容器 中的对齐方式 例子 1 <?xml v