亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android開發(fā)實現(xiàn)布局幀布局霓虹燈效果示例

 更新時間:2019年04月12日 12:00:24   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)實現(xiàn)布局幀布局霓虹燈效果,涉及Android界面布局、資源文件操作及屬性設置等相關技巧,需要的朋友可以參考下

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

效果圖:

實現(xiàn)方式:

FrameLayout中,設置8個TextView,在主函數(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資源文件設置:

<?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第三版

更多關于Android相關內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設計有所幫助。

相關文章

  • android實現(xiàn)可上下回彈的scrollview

    android實現(xiàn)可上下回彈的scrollview

    這篇文章主要為大家詳細介紹了android實現(xiàn)可上下回彈的scrollview,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 聊聊GridView實現(xiàn)拖拽排序及數(shù)據(jù)交互的問題

    聊聊GridView實現(xiàn)拖拽排序及數(shù)據(jù)交互的問題

    這篇文章主要介紹了聊聊GridView實現(xiàn)拖拽排序及數(shù)據(jù)交互的問題,整體實現(xiàn)思路是通過在一個容器里放置兩個dragview,DragView里面進行View的動態(tài)交換以及數(shù)據(jù)交換,具體實現(xiàn)代碼跟隨小編一起看看吧
    2021-11-11
  • 基于界面適配華為手機的虛擬按鍵的解決方法

    基于界面適配華為手機的虛擬按鍵的解決方法

    下面小編就為大家分享一篇基于界面適配華為手機的虛擬按鍵的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android中發(fā)送有序廣播案例代碼

    Android中發(fā)送有序廣播案例代碼

    本篇文章主要介紹了Android中發(fā)送有序廣播案例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • 使用Compose制作抖音快手視頻進度條Loading動畫效果

    使用Compose制作抖音快手視頻進度條Loading動畫效果

    這篇文章主要為大家介紹了使用Compose制作抖音快手視頻進度條Loading動畫效果,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Android 極光推送別名與標簽方式

    Android 極光推送別名與標簽方式

    這篇文章主要介紹了Android 極光推送別名與標簽方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Android fragment實現(xiàn)多個頁面切換效果

    Android fragment實現(xiàn)多個頁面切換效果

    這篇文章主要為大家詳細介紹了fragment實現(xiàn)多個頁面切換效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • ViewPager2滑動沖突解決方案

    ViewPager2滑動沖突解決方案

    這篇文章主要介紹了ViewPager2滑動沖突解決方案,幫助大家更好的進行Android開發(fā),感興趣的朋友可以了解下
    2020-12-12
  • Android實現(xiàn)啟動頁倒計時效果

    Android實現(xiàn)啟動頁倒計時效果

    這篇文章主要介紹了Android實現(xiàn)啟動頁倒計時效果的示例代碼,幫助大家更好的理解和學習使用Android進行開發(fā),感興趣的朋友可以了解下
    2021-04-04
  • Android實現(xiàn)簡單斷點續(xù)傳和下載到本地功能

    Android實現(xiàn)簡單斷點續(xù)傳和下載到本地功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)簡單斷點續(xù)傳和下載到本地功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11

最新評論