如何在 CollapsingToolbarLayout android 中定期更改图像?

How to change image periodically inside CollapsingToolbarLayout android?

我想在 CollapsingToolbarLayout 内周期性地旋转多个图像,例如 Google Play Newsstand Application

我已经在此处上传了该应用程序的 3 个屏幕截图: First Second Third

我使用以下代码创建了 CollapsingToolbarLayout

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/detail_backdrop_height"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp" >

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_collapseMode="parallax"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/image" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

如何在 CollapsingToolbarLayout 中定期(在特定时间间隔后)更改图像?

注: Look at here for creating animation on ImageView while changing image

  1. 使用 findViewById()
  2. 获取对 ImageView 的引用
  3. 您需要一个 Runnable 来更新 ImageView
  4. 中显示的图像
  5. 您可以使用HanlderpostDelayed()方法定期运行Runnable代码

    final Handler handler = new Handler();   
    final Runnable runnable = new Runnable() {
    
        @Override   
        public void run() {   
            //TODO: update image here   
            handler.postDelayed(this, INTERVAL);   
        }   
    }   
    handler.postDelayed(runnable, INTERVAL);