How to make view pager of images as free market app and others

3

I would like to ask your help on how to make this layout that neither the Free Market app and others out there like Viva Real Estate. The layout I need is the same as this image I'm putting below, It would be a toolbar the same way and just below a view pager with those balls that pass the images and clicking on the images they stay in fullscreen and continue with indicator balls. Below the image viewer pager I would put the rest of my layout. The main part that I need of your help would be this same, from the slide of images with the drag of the fingers with polka-dot counter and fullscreen as well. In Design material.

Could you help me?

    
asked by anonymous 17.10.2015 / 23:05

2 answers

2

I was able to resolve my issue based on @Wakim's response and comments. I suggest first reading his post and then see my code. The Layout really looked good as the "WhatsApp" on a contact's profile screen.

Below is the code to get Layout the way I wanted it (slightly different from the "eBay")

<?xml version="1.0" encoding="utf-8"?>
<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/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

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

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"/>

            <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/pagerIndicator"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_gravity="center|bottom"
                android:fitsSystemWindows="true"
                android:layout_marginBottom="16dp"/>

        </FrameLayout>

        <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/AppTheme.PopupOverlay"/>

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:clickable="true"
    android:src="@drawable/ic_image_photo_camera"
    app:layout_anchor="@id/app_bar_layout"
        app:layout_anchorGravity="bottom|right|end"/>

</android.support.design.widget.CoordinatorLayout>

Every detail in this code is important, even the order of Toolbar , Padding of CirclePageIndicator , etc.

Thanks @Wakim for the help.

Credits:

  • @Wakim Reply
  • Toolbar animation with scroll
  • Link indicated by @Wakim in my question comments
  • 23.10.2015 / 22:29
    4

    Starting from the beginning, google's new library, Design Library , brings several components ready with some common Material Design interactions.

    Just include the library as a dependency on your build.gradle :

    compile 'com.android.support:design:23.1.0'
    
    # Outras dependencias implicitas...
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    

    Only here comes the surprise ... Along with Design Library comes other 3 that it also depends ... If you already use them, no problem. But you can overhead your app if you do not use them.

    In addition, to implement the indicators I recommend using the ViewPagerIndicator of Jake Wharton.

    With this, the dependency has to be included as well:

    compile 'com.viewpagerindicator:library:2.4.1@aar'
    

    But as JakeWharton did not publish his library as an AAR, you need to include the following repositories to your project after the declaration of plugins:

    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
    }
    

    Following the Antonio Leiva's tutorial on CollapsingToolbarLayout

    Let's have the following layout (well boilerplate: /):

    <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/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp"
                android:fitsSystemWindows="true">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="pin" />
    
                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    
                    <android.support.v4.view.ViewPager
                        android:id="@+id/pager"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax" />
    
                    <com.viewpagerindicator.CirclePageIndicator
                        android:id="@+id/indicator"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom"
                        android:layout_marginBottom="16dp" />
                </FrameLayout>
    
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
            <FrameLayout
                android:id="@+id/fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
    
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
    

    Some comments:

    • For the scrolling effect to work, you need to use components with the Nested Scroll function. I know only 2: NestedScrollView and RecyclerView . I do not know if ListView or GridView works well without any customization.

    • Some components have some "crashes" during the Scroll, if this happens, I recommend the library smooth-app-bar-layout that provides the same components with behavior improvements.

    I think the setup of ViewPager is known, but below is how to connect CirclePageIndicator and ViewPager :

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    
    pager.setAdapter(...);
    
    CirclePageIndicator circleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
    circleIndicator.setViewPager(pager);
    

    Edit: Some feedback adjustments:

    1) Addition of layout_gravity="bottom" and layout_marginBottom="16p" in CircleViewIndicator .

    2) Change from android:layout_height from CollapsingToolbarLayout to android:layout_height="wrap_content" .

    There are good references to the new components:

    18.10.2015 / 00:29