Giter Site home page Giter Site logo

collapsingavatartoolbar's Introduction

Collapsing Avatar Toolbar

This little library demonstrates how to add a Collapsible Toolbar to your application with an avatar that moves and expands as seen in the Telegram Android application.

This library consist in one single view, and uses the Design Support Library.

Demo

Check out the sample project included.

sample

Gradle

dependencies {
    compile 'com.sloydev:collapsingavatartoolbar:1.0.0'
}

Usage

Add com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar to your layout:

<com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar
  android:layout_width="wrap_content"
  android:layout_height="?attr/actionBarSize"
  app:collapsedPadding="@dimen/collapsedPadding"
  app:expandedPadding="@dimen/expandedPadding"
  app:collapsedImageSize="@dimen/collapsedImageSize"
  app:expandedImageSize="@dimen/expandedImageSize"
  app:collapsedTextSize="@dimen/collapsedTextSize"
  app:expandedTextSize="@dimen/expandedTextSize"
  >

It must be placed inside a CollapsingToolbarLayout with a sibling Toolbar, like this:

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

    <android.support.design.widget.AppBarLayout
      ...
      android:layout_height="@dimen/expanded_toolbar_height"
      >
      
        <android.support.design.widget.CollapsingToolbarLayout
    	  ...
          app:contentScrim="?attr/colorPrimary"
          app:layout_scrollFlags="scroll|exitUntilCollapsed"
          >

            <android.support.v7.widget.Toolbar
        	  ...
              app:layout_collapseMode="pin"
              />

            <com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar
              ...
              >

                <de.hdodenhof.circleimageview.CircleImageView
                  android:id="@id/cat_avatar"
        	      ...
                  />

               	<TextView 
                  android:id="@id/cat_title"
                  ...
                  />
                
            </com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar>

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

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

    <!-- The rest of your activity layout -->
    ...

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

Important points

  • CollapsingAvatarToolbar must be placed inside an AppBarLayout, wrapped with a CollapsingToolbarLayout. Check out the Android Design Support library for more info.

  • CollapsingAvatarToolbar must have a sibling Toolbar, which will be shown below it for navigation controls and menu items. If you don't want to use a Toolbar... well we should talk about it.

  • Expanded height will be determined by the AppBarLayout's height.

  • Collapsed height will be determined by the Toolbar's height.

  • You must provide the avatar and title views inside CollapsingAvatarToolbar, with the exact same ids shown above. Note: these are the library's ids, not your owns.

  • You can use any kind of TextView for the title, and any view you want for the avatar. I used hdodenhof's CircleImageView in the sample, but that's up to you.

  • You can also add more views inside CollapsingAvatarToolbar. Take a look at the sample for an example with subtitle.

  • All custom attributes are optional. If not provided defaults will be used.

Contribute

Improvements are most than welcome. Feel free to send a Pull Request or open an Issue.

I am pretty bad at explaining myself. Check out the sample project for implementation details or ask me anything you want to know.

External libraries

collapsingavatartoolbar's People

Contributors

sloy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.