日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

android的帧布局,七、Android帧布局FrameLayout和霓虹灯效果

發(fā)布時(shí)間:2023/12/10 Android 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android的帧布局,七、Android帧布局FrameLayout和霓虹灯效果 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

幀布局容器為每個(gè)加入其中的組件創(chuàng)建一個(gè)空白的區(qū)域(稱(chēng)為一幀),所有每個(gè)子組件占據(jù)一幀,這些幀都會(huì)根據(jù)gravity屬性執(zhí)行自動(dòng)對(duì)齊。

FrameLayout的常用XML屬性和相關(guān)方法

XML屬性

相關(guān)方法

說(shuō)??明

android:foreground

setForeground(Drawable)

設(shè)置該幀布局容器的前景圖像

android:foregroundGravity

setForegroundGravity(int)

定義繪制前景圖像的gravity屬性

下面的布局界面定義使用FrameLayout布局,并向該布局容器中添加了7個(gè)TextView,這7個(gè)TextView的高度完全相同,而寬度逐漸減少——這保證最先添加的TextView不會(huì)被完全遮擋;而且設(shè)置了7個(gè)TextView的背景色漸變。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/View01"

android:layout_width="210dp"

android:layout_height="200dp"

android:background="#ff0000"/>

android:id="@+id/View02"

android:layout_width="180dp"

android:layout_height="200dp"

android:background="#dd0000"/>

android:id="@+id/View03"

android:layout_width="150dp"

android:layout_height="200dp"

android:background="#bb0000"/>

android:id="@+id/View04"

android:layout_width="120dp"

android:layout_height="200dp"

android:background="#990000"/>

android:id="@+id/View05"

android:layout_width="90dp"

android:layout_height="200dp"

android:background="#770000"/>

android:id="@+id/View06"

android:layout_width="60dp"

android:layout_height="200dp"

android:background="#550000"/>

android:id="@+id/View07"

android:layout_width="30dp"

android:layout_height="200dp"

android:background="#330000"/>

效果如圖:

顏色漸變.jpg

霓虹燈效果

如果考慮輪換上面幀布局中的7個(gè)TextView的背景色,就會(huì)看到上面的顏色漸變條不斷地變化,就像大街上的霓虹燈。

private int currentColor = 0;

//定義一個(gè)顏色數(shù)組

final int[] colors = new int[]{

R.color.color7,

R.color.color6,

R.color.color5,

R.color.color4,

R.color.color3,

R.color.color2,

R.color.color1

};

final int[] names = new int[]{

R.id.View01,

R.id.View02,

R.id.View03,

R.id.View04,

R.id.View05,

R.id.View06,

R.id.View07,

};

TextView[] views = new TextView[7];

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity3);

for (int i = 0; i < 7; i++) {

views[i] = findViewById(names[i]);

}

@SuppressLint("HandlerLeak")

final Handler handler = new Handler() {

@Override

public void handleMessage(@NonNull Message msg) {

if (msg.what == 0x1122) {

for (int i = 0; i < 7 - currentColor; i++) {

views[i].setBackgroundResource(colors[i + currentColor]);

}

for (int i = 7 - currentColor, j = 0; i < 7; i++, j++) {

views[i].setBackgroundResource(colors[j]);

}

}

super.handleMessage(msg);

}

};

//定義一個(gè)線程周期性地改變currentColor變量值

new Timer().schedule(new TimerTask() {

@Override

public void run() {

currentColor++;

if (currentColor >= 6) {

currentColor = 0;

}

Message m = new Message();

m.what = 0x1122;

handler.sendMessage(m);

}

}, 0, 500);

}

總結(jié)

以上是生活随笔為你收集整理的android的帧布局,七、Android帧布局FrameLayout和霓虹灯效果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。