【问题标题】:How to change image periodically inside CollapsingToolbarLayout android?如何在 CollapsingToolbarLayout android 中定期更改图像?
【发布时间】:2015-09-13 13:06:02
【问题描述】:

我想在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

【问题讨论】:

    标签: android imageview android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout


    【解决方案1】:
    1. 使用findViewById() 获取对ImageView 的引用
    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);
      

    【讨论】:

    • 那么鲜为人知的 ViewAnimator 小部件呢?
    • @WindRider 这是一个有效的选项,具体取决于用例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    相关资源
    最近更新 更多