2

I want to rotate multiple images periodically inside CollapsingToolbarLayout like Google Play Newsstand Application

I have uploaded 3 screenshots of that app here: First Second Third

I have created CollapsingToolbarLayout using below code.

<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>

How to change image periodically(after some specific interval) inside CollapsingToolbarLayout ?

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

Community
  • 1
  • 1
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85

1 Answers1

3
  1. Get a reference to the ImageView using findViewById()
  2. You need a Runnable which will update the image displayed in the ImageView
  3. You can use the postDelayed() method of a Hanlder to run the Runnable code periodically

    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);
    
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85
LordRaydenMK
  • 13,074
  • 5
  • 50
  • 56