Android開(kāi)發(fā)實(shí)現(xiàn)布局幀布局霓虹燈效果示例
本文實(shí)例講述了Android開(kāi)發(fā)實(shí)現(xiàn)布局幀布局霓虹燈效果。分享給大家供大家參考,具體如下:
效果圖:

實(shí)現(xiàn)方式:
FrameLayout中,設(shè)置8個(gè)TextView,在主函數(shù)中,設(shè)計(jì)顏色數(shù)組,通過(guò)有序替換他們顏色,實(shí)現(xiàn)漸變效果。
java代碼:MainActivity
public class MainActivity extends AppCompatActivity {
private int currentColor = 0;
/*
定義顏色數(shù)組 實(shí)現(xiàn)顏色切換 類似魚(yú)片切換
*/
final int[] colors = new int[]{
R.color.color1,
R.color.color2,
R.color.color3,
R.color.color4,
R.color.color5,
R.color.color6,
R.color.color7,
R.color.color8
};
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,
R.id.view08
};
TextView[] views = new TextView[names.length];
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg){
//表明消息由本日程發(fā)送
if(msg.what == 0x123){
for(int i = 0; i < names.length; i++){//更換顏色
views[i].setBackgroundResource(colors[ (i + currentColor) % names.length]);
}
currentColor++;
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 0; i < names.length; i++){//更換顏色
views[i] = (TextView) findViewById(names[i]);
}
//定義一個(gè)線程改變current變量值
new Timer().schedule(new TimerTask() {
@Override
public void run() {
//發(fā)送一條空消息通知系統(tǒng)改變6個(gè)TextView顏色
handler.sendEmptyMessage(0x123);
}
}, 0, 300);
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--依次定義六個(gè)TextView,先定義的位于底層
后定義的位于上層-->
<TextView
android:id="@+id/view01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="320dp"
android:height="320dp"
android:background="#ea7500"/>
<TextView
android:id="@+id/view02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="280dp"
android:height="280dp"
android:background="#ff8000"/>
<TextView
android:id="@+id/view03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="240dp"
android:height="240dp"
android:background="#ff9224"/>
<TextView
android:id="@+id/view04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="200dp"
android:height="200dp"
android:background="#ffa042"/>
<TextView
android:id="@+id/view05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="160dp"
android:height="160dp"
android:background="#ffaf60"/>
<TextView
android:id="@+id/view06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="120dp"
android:height="120dp"
android:background="#ffa042"/>
<TextView
android:id="@+id/view07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="80dp"
android:height="80dp"
android:background="#ff9224"/>
<TextView
android:id="@+id/view08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:width="40dp"
android:height="40dp"
android:background="#ff8000"/>
</FrameLayout>
color資源文件設(shè)置:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#008577</color> <color name="colorPrimaryDark">#00574B</color> <color name="colorAccent">#D81B60</color> <color name="color1">#844200</color> <color name="color2">#d26900</color> <color name="color3">#ff9224</color> <color name="color4">#ffbb77</color> <color name="color5">#ffd1a4</color> <color name="color6">#ffaf60</color> <color name="color7">#ff8000</color> <color name="color8">#bb5e00</color> </resources>
改編自瘋狂java第三版
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android手機(jī)顯示多彩霓虹燈效果
- Android Shader應(yīng)用開(kāi)發(fā)之霓虹閃爍文字效果
- Android圖像處理之霓虹濾鏡效果
- Android布局之幀布局FrameLayout詳解
- Android布局之FrameLayout幀布局
- Android實(shí)現(xiàn)氣泡布局/彈窗效果 氣泡尖角方向及偏移量可控
- Android布局實(shí)現(xiàn)圓角邊框效果
- Android動(dòng)畫(huà)效果之自定義ViewGroup添加布局動(dòng)畫(huà)(五)
- Android給布局、控件加陰影效果的示例代碼
- Android編程實(shí)現(xiàn)圓角邊框布局效果的方法
- Android布局控件DrawerLayout實(shí)現(xiàn)完美側(cè)滑效果
相關(guān)文章
android實(shí)現(xiàn)可上下回彈的scrollview
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)可上下回彈的scrollview,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
聊聊GridView實(shí)現(xiàn)拖拽排序及數(shù)據(jù)交互的問(wèn)題
這篇文章主要介紹了聊聊GridView實(shí)現(xiàn)拖拽排序及數(shù)據(jù)交互的問(wèn)題,整體實(shí)現(xiàn)思路是通過(guò)在一個(gè)容器里放置兩個(gè)dragview,DragView里面進(jìn)行View的動(dòng)態(tài)交換以及數(shù)據(jù)交換,具體實(shí)現(xiàn)代碼跟隨小編一起看看吧2021-11-11
使用Compose制作抖音快手視頻進(jìn)度條Loading動(dòng)畫(huà)效果
這篇文章主要為大家介紹了使用Compose制作抖音快手視頻進(jìn)度條Loading動(dòng)畫(huà)效果,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
Android fragment實(shí)現(xiàn)多個(gè)頁(yè)面切換效果
這篇文章主要為大家詳細(xì)介紹了fragment實(shí)現(xiàn)多個(gè)頁(yè)面切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
Android實(shí)現(xiàn)啟動(dòng)頁(yè)倒計(jì)時(shí)效果
這篇文章主要介紹了Android實(shí)現(xiàn)啟動(dòng)頁(yè)倒計(jì)時(shí)效果的示例代碼,幫助大家更好的理解和學(xué)習(xí)使用Android進(jìn)行開(kāi)發(fā),感興趣的朋友可以了解下2021-04-04
Android實(shí)現(xiàn)簡(jiǎn)單斷點(diǎn)續(xù)傳和下載到本地功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單斷點(diǎn)續(xù)傳和下載到本地功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11

