欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于RxJava實現(xiàn)酷炫啟動頁

 更新時間:2016年07月27日 15:20:15   作者:簡書作者  
本文介紹怎樣利用RxJava來實現(xiàn)Android的啟動頁,啟動頁的效果非???,有需要的朋友們可以參考。

前言

RxJava 在 GitHub 主頁上的自我介紹是 "a library for composing asynchronous and event-based programs using observable sequences for the Java VM"(一個在 Java VM 上使用可觀測的序列來組成異步的、基于事件的程序的庫)。這就是 RxJava ,概括得非常精準(zhǔn)。

之前注意到coding APP啟動頁很是酷炫,今天我們使用RxJava和屬性動畫模仿實現(xiàn)其效果。

先來看看效果

一、新建啟動頁WelcomeActivity

注意,我們這里讓WelcomeActivity繼承Activity不要繼承AppCompatActivity,因為AppCompatActivity會默認(rèn)去加載主題,造成卡頓

  public class WelcomeActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
  }
}

二、定義引導(dǎo)頁布局activity_welcome.xml

不多說直接上代碼:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <ImageView
    android:id="@+id/iv_entry"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    android:src="@drawable/welcomimg1"/>

  <View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/welcomimg_bg"/>


  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="100dp"
    android:gravity="center"
    android:text="xialong"
    android:textColor="@android:color/white"
    android:textSize="23sp"/>

  <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/google_logo"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="60dp"
    android:layout_centerInParent="true"
    android:tint="@android:color/white" />
</RelativeLayout>

這里我們用了相對布局,在ImageView上覆蓋一個View,該View用漸變色背景welcomimg_bg.xml以暗化圖片,

welcomimg_bg.xml代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

  <gradient
    android:angle="90"
    android:startColor="@color/black"
    android:endColor="@android:color/transparent"
    />

</shape>

其中startColor表示起始顏色,endColor表示結(jié)束顏色,angle=90 表示顏色從下往上漸變。

三、隨機選取圖片并使用RxJava啟動動畫

最后我們的WelcomeActivity.java長這樣:

public class WelcomeActivity extends Activity {

  @Bind(R.id.iv_entry)
  ImageView mIVEntry;

  private static final int ANIM_TIME = 2000;

  private static final float SCALE_END = 1.15F;

  private static final int[] Imgs={
      R.drawable.welcomimg1,R.drawable.welcomimg2,
      R.drawable.welcomimg3,R.drawable.welcomimg4,
      R.drawable.welcomimg5, R.drawable.welcomimg6,
      R.drawable.welcomimg7,R.drawable.welcomimg8,
      R.drawable.welcomimg9,R.drawable.welcomimg10,
      R.drawable.welcomimg11,R.drawable.welcomimg12,};

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
    ButterKnife.bind(this);

    Random random = new Random(SystemClock.elapsedRealtime());//SystemClock.elapsedRealtime() 從開機到現(xiàn)在的毫秒數(shù)(手機睡眠(sleep)的時間也包括在內(nèi))
    mIVEntry.setImageResource(Imgs[random.nextInt(Imgs.length)]);

    Observable.timer(1000, TimeUnit.MILLISECONDS)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Action1<Long>()
        {

          @Override
          public void call(Long aLong)
          {
            startAnim();
          }
        });
  }


  private void startAnim() {

    ObjectAnimator animatorX = ObjectAnimator.ofFloat(mIVEntry, "scaleX", 1f, SCALE_END);
    ObjectAnimator animatorY = ObjectAnimator.ofFloat(mIVEntry, "scaleY", 1f, SCALE_END);

    AnimatorSet set = new AnimatorSet();
    set.setDuration(ANIM_TIME).play(animatorX).with(animatorY);
    set.start();

    set.addListener(new AnimatorListenerAdapter()
    {

      @Override
      public void onAnimationEnd(Animator animation)
      {

        startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
        WelcomeActivity.this.finish();
      }
    });
  }
}

這里的RxJava使用了timer操作符,它的意思是延遲執(zhí)行某個操作,第一個參數(shù)表示延遲時間,第二個參數(shù)是時間單位。

好了,就醬。以上就是用RxJava打造酷炫啟動頁的全部內(nèi)容,希望本文對大家學(xué)習(xí)Android開發(fā)有所幫助。

相關(guān)文章

  • Android開發(fā)優(yōu)化之Apk瘦身優(yōu)化指南

    Android開發(fā)優(yōu)化之Apk瘦身優(yōu)化指南

    隨著業(yè)務(wù)快速發(fā)展,各種業(yè)務(wù)功能上線,版本不斷迭代,apk體積也越來越大,下面這篇文章主要給大家介紹了關(guān)于Android開發(fā)優(yōu)化之Apk瘦身優(yōu)化的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • Android 分享功能的實現(xiàn)代碼

    Android 分享功能的實現(xiàn)代碼

    這篇文章主要介紹了Android 分享功能的實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android DrawerLayout帶有側(cè)滑功能的布局類(1)

    Android DrawerLayout帶有側(cè)滑功能的布局類(1)

    這篇文章主要為大家詳細介紹了Android DrawerLayout帶有側(cè)滑功能的布局類,感興趣的小伙伴們可以參考一下
    2016-07-07
  • 你用不慣 RxJava,只因缺了這把鑰匙(推薦)

    你用不慣 RxJava,只因缺了這把鑰匙(推薦)

    這篇文章主要介紹了RxJava操作符,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Android自定義UI之粒子效果

    Android自定義UI之粒子效果

    這篇文章主要為大家詳細介紹了Android自定義UI之粒子效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Android?View的事件體系教程詳解

    Android?View的事件體系教程詳解

    這篇文章主要為大家介紹了Android?View的事件體系教程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪
    2022-03-03
  • 淺談Android Studio 4.1 更新內(nèi)容

    淺談Android Studio 4.1 更新內(nèi)容

    這篇文章主要介紹了淺談Android Studio 4.1 更新內(nèi)容,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Android 使用 ViewPager循環(huán)廣告位的實現(xiàn)

    Android 使用 ViewPager循環(huán)廣告位的實現(xiàn)

    本文給大家分享android使用 ViewPager循環(huán)廣告位的實現(xiàn),感興趣的朋友一起學(xué)習(xí)吧
    2015-11-11
  • Android CountDownTimer實現(xiàn)定時器和倒計時效果

    Android CountDownTimer實現(xiàn)定時器和倒計時效果

    這篇文章主要為大家詳細介紹了Android CountDownTimer實現(xiàn)定時器和倒計時效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Android自定義EditText實現(xiàn)淘寶登錄功能

    Android自定義EditText實現(xiàn)淘寶登錄功能

    這篇文章主要為大家詳細介紹了Android自定義EditText實現(xiàn)淘寶登錄功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12

最新評論