本篇文章為大家展示了怎么在Android中實現(xiàn)一個布局幀布局霓虹燈效果,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

創(chuàng)新互聯(lián)公司主營安寧網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),安寧h5微信小程序搭建,安寧網(wǎng)站營銷推廣歡迎安寧等地區(qū)企業(yè)咨詢
實現(xiàn)方式:
FrameLayout中,設(shè)置8個TextView,在主函數(shù)中,設(shè)計顏色數(shù)組,通過有序替換他們顏色,實現(xiàn)漸變效果。
java代碼:MainActivity
public class MainActivity extends AppCompatActivity {
private int currentColor = 0;
/*
定義顏色數(shù)組 實現(xiàn)顏色切換 類似魚片切換
*/
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]);
}
//定義一個線程改變current變量值
new Timer().schedule(new TimerTask() {
@Override
public void run() {
//發(fā)送一條空消息通知系統(tǒng)改變6個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"> <!--依次定義六個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>
上述內(nèi)容就是怎么在Android中實現(xiàn)一個布局幀布局霓虹燈效果,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章標題:怎么在Android中實現(xiàn)一個布局幀布局霓虹燈效果
網(wǎng)頁鏈接:http://www.yijiale78.com/article24/gcesje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、外貿(mào)建站、全網(wǎng)營銷推廣、電子商務(wù)、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)