Code Monkey home page Code Monkey logo

subtitle-collapsingtoolbar's Introduction

SubtitleCollapsingToolbarLayout

This layout is a CollapsingToolbarLayout with subtitle support. Ever wondered how WhatsApp did with their contacts profile activity? this layout is mimicking that behavior.

Subtitle Collapsing Toolbar Layout

Assuming you already knew how to use the standard CollapsingToolbarLayout material. if you never use that before this tutorial have good explanation on how to do it.

Usage

first, clone this repo:

git clone https://github.com/ahmadmuzakki29/subtitle-collapsingtoolbar

then on Android Studio you can import the module with File->New->Import Module and choose module :subtitlecollapsingtoolbar inside downloaded folder

Available new attributes:

app:subtitle="string"
app:collapsedSubtitleAppearance="reference"
app:expandedSubtitleAppearance="reference"

Quick XML snippet :

<?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:layout_width="match_parent"
        android:layout_height="192dp"
        android:background="?attr/colorPrimary"
        android:fitsSystemWindows="true">

        <com.muzakki.ahmad.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="@color/colorAccent"
            app:collapsedTitleTextAppearance="@style/title.collapsed"
            app:expandedTitleTextAppearance="@style/title.expanded"
            app:collapsedSubtitleAppearance="@style/subtitle"
            app:expandedSubtitleAppearance="@style/subtitle"
            app:title="Pendet"
            app:subtitle="Bali, Indonesia"
            android:fitsSystemWindows="true"
            >
            <ImageView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:src="@drawable/pendet_dance"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                />
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>

        </com.muzakki.ahmad.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">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:text="Pendet is a traditional dance from Bali, Indonesia, in which offerings are made to purify the temple or theater as a prelude to ceremonies or other dances. Pendet is typically performed by young girls, carrying bowls of flower petals, handfuls of which are cast into the air at various times in the dance. Pendet can be thought of as a dance of greeting, to welcome the audience and invite spirits to enjoy a performance." />
    </android.support.v4.widget.NestedScrollView>

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

subtitle-collapsingtoolbar's People

Contributors

jekiapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

subtitle-collapsingtoolbar's Issues

Gravity Right doesnt work

Using collapsingToolbar.setExpandedTitleGravity(Gravity.END); or collapsingToolbar.setExpandedTitleGravity(Gravity.RIGHT);doesnt work. Title and subtitle stay at left

cannot find symbol variable CollapsingAppBarLayout_LayoutParams

myproyect/subtitlecollapsingtoolbar/src/main/java/com/muzakki/ahmad/widget/CollapsingToolbarLayout.java
Error:(1069, 32) error: cannot find symbol variable CollapsingAppBarLayout_LayoutParams
Error:(1071, 32) error: cannot find symbol variable CollapsingAppBarLayout_LayoutParams_layout_collapseMode
Error:(1074, 32) error: cannot find symbol variable CollapsingAppBarLayout_LayoutParams_layout_collapseParallaxMultiplier

Error:Execution failed for task ':subtitlecollapsingtoolbar:compileReleaseJavaWithJavac'.
Compilation failed; see the compiler error output for details.

the problem is with this method

 public LayoutParams(Context c, AttributeSet attrs) {
            super(c, attrs);

            TypedArray a = c.obtainStyledAttributes(attrs,
                    R.styleable.CollapsingAppBarLayout_LayoutParams);
            mCollapseMode = a.getInt(
                    R.styleable.CollapsingAppBarLayout_LayoutParams_layout_collapseMode,
                    COLLAPSE_MODE_OFF);
            setParallaxMultiplier(a.getFloat(
                    R.styleable.CollapsingAppBarLayout_LayoutParams_layout_collapseParallaxMultiplier,
                    DEFAULT_PARALLAX_MULTIPLIER));
            a.recycle();
        }

there is not a expandedSubtitleTextAppearance

is necessary to have a expandedSubtitleTextAppearance like expandedTitleTextAppearance because also the subtitle needs a shadow because if the word is white and the background is white so the word wont be visible

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.