国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

霓虹燈效果

2019-11-09 15:46:03
字體:
供稿:網(wǎng)友

1、使用FrameLayout實現(xiàn)霓虹效果

package com.example.nihongdeng;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;import com.example.customdemo.R;import java.util.Timer;import java.util.TimerTask;public class NiHongActivity extends AppCompatActivity {    PRivate int  currentColor=0;    //定義顏色數(shù)組    final int [] colorList=new int[]{            R.color.color1,            R.color.color2,            R.color.color3,            R.color.color4,            R.color.color5,            R.color.color6,    };    final int[] names=new int[]{            R.id.view01,R.id.view02,R.id.view03,R.id.view04,R.id.view05,R.id.view06    };    TextView[] textViews=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++) {                    textViews[i].setBackgroundResource(colorList[(i+currentColor)%names.length]);                }                currentColor++;            }            super.handleMessage(msg);        }    };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_ni_hong);        for (int i = 0; i <names.length ; i++) {            textViews[i]= (TextView) findViewById(names[i]);        }        //定義一個線程周期性改變的currentColor變量值        new Timer().schedule(new TimerTask() {            @Override            public void run() {                //發(fā)一條空消息通知系統(tǒng)改變6個textView的背景色                handler.sendEmptyMessage(0x123);            }        },0,200);    }}

2、布局文件

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_ni_hong"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.nihongdeng.NiHongActivity">    <TextView        android:id="@+id/view01"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:width="320pt"        android:height="320pt"        android:background="#f00"/>    <TextView        android:id="@+id/view02"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:width="280pt"        android:height="280pt"        android:background="#0f0"/>    <TextView        android:id="@+id/view03"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:width="240pt"        android:height="240pt"        android:background="#00f"/>    <TextView        android:id="@+id/view04"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:width="200pt"        android:height="200pt"        android:background="#ff0"/>    <TextView        android:id="@+id/view05"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:width="160pt"        android:height="160pt"        android:background="#f0f"/>    <TextView        android:id="@+id/view06"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:width="120pt"        android:height="120pt"        android:background="#0ff"/>    </FrameLayout>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 肇庆市| 同心县| 北京市| 明星| 玉田县| 孟连| 怀仁县| 大竹县| 北流市| 海丰县| 灵石县| 栾城县| 安徽省| 新丰县| 澎湖县| 塘沽区| 翁牛特旗| 无极县| 衡阳县| 额尔古纳市| 凌云县| 承德市| 凤翔县| 洞头县| 霍林郭勒市| 皋兰县| 崇明县| 北海市| 大厂| 同德县| 青浦区| 巍山| 子长县| 远安县| 堆龙德庆县| 达日县| 武安市| 宁武县| 罗源县| 武功县| 靖西县|