2

我想像Google Play 报亭应用程序CollapsingToolbarLayout一样在内部定期旋转多个图像

我在这里上传了该应用程序的 3 个屏幕截图: 第一 第二 第三

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

注意: 查看此处以在更改图像时在 ImageView 上创建动画

4

1 回答 1

3
  1. 获取使用的ImageView参考findViewById()
  2. 您需要一个Runnable将更新显示在ImageView
  3. 您可以使用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);
    
于 2015-09-13T13:34:11.943 回答