Collapsing Toolbar layout with logo, title, subtitle in toolbar
I want do this but with Collapsing toolbar layout or display the logo and title in toolbar after scroll.
<!-- Toolbars -->
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background_1"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/avatar_image"
android:layout_width="@dimen/circular_image_avatar"
android:layout_height="@dimen/circular_image_avatar"
android:gravity="center"
android:scaleType="centerCrop"
android:src="@drawable/ic_placerholder"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:transitionName="image_toolbar"/>
<TextView
android:id="@+id/profile_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name title"
android:textAlignment="center"
android:layout_marginTop="@dimen/item_padding_top_bottom"
android:gravity="center"
style="@style/titleText_toolbar"
android:layout_below="@+id/avatar_image"
android:transitionName="title_toolbar"/>
<TextView
android:id="@+id/profile_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAlignment="center"
android:gravity="center"
style="@style/captionText_toolbar"
android:layout_below="@+id/profile_title" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<!-- avatar image and title, subtitle -->
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Please help me
android android-layout toolbar material-design android-collapsingtoolbarlayout
add a comment |
I want do this but with Collapsing toolbar layout or display the logo and title in toolbar after scroll.
<!-- Toolbars -->
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background_1"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/avatar_image"
android:layout_width="@dimen/circular_image_avatar"
android:layout_height="@dimen/circular_image_avatar"
android:gravity="center"
android:scaleType="centerCrop"
android:src="@drawable/ic_placerholder"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:transitionName="image_toolbar"/>
<TextView
android:id="@+id/profile_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name title"
android:textAlignment="center"
android:layout_marginTop="@dimen/item_padding_top_bottom"
android:gravity="center"
style="@style/titleText_toolbar"
android:layout_below="@+id/avatar_image"
android:transitionName="title_toolbar"/>
<TextView
android:id="@+id/profile_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAlignment="center"
android:gravity="center"
style="@style/captionText_toolbar"
android:layout_below="@+id/profile_title" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<!-- avatar image and title, subtitle -->
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Please help me
android android-layout toolbar material-design android-collapsingtoolbarlayout
What code have you tried? What problems are you running into? Describe it more and we will (probably) help.
– Tristan Wiley
Jul 12 '15 at 16:14
i.imgur.com/Yj7pe5Y.jpg i.imgur.com/AUVokgc.jpg i.imgur.com/dqWq3Fp.jpg Sorry I don't have 10 reputation for post images :(
– tonilopezmr
Jul 12 '15 at 16:20
The code is irrelevant in this case, I want know how to do it
– tonilopezmr
Jul 12 '15 at 16:45
hi @tonilopezmr could you post how you achieved this?
– Hardik Amal
Jun 2 '16 at 9:31
@HardikAmal check out this github.com/saulmm/CoordinatorBehaviorExample
– tonilopezmr
Jun 9 '16 at 11:35
add a comment |
I want do this but with Collapsing toolbar layout or display the logo and title in toolbar after scroll.
<!-- Toolbars -->
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background_1"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/avatar_image"
android:layout_width="@dimen/circular_image_avatar"
android:layout_height="@dimen/circular_image_avatar"
android:gravity="center"
android:scaleType="centerCrop"
android:src="@drawable/ic_placerholder"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:transitionName="image_toolbar"/>
<TextView
android:id="@+id/profile_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name title"
android:textAlignment="center"
android:layout_marginTop="@dimen/item_padding_top_bottom"
android:gravity="center"
style="@style/titleText_toolbar"
android:layout_below="@+id/avatar_image"
android:transitionName="title_toolbar"/>
<TextView
android:id="@+id/profile_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAlignment="center"
android:gravity="center"
style="@style/captionText_toolbar"
android:layout_below="@+id/profile_title" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<!-- avatar image and title, subtitle -->
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Please help me
android android-layout toolbar material-design android-collapsingtoolbarlayout
I want do this but with Collapsing toolbar layout or display the logo and title in toolbar after scroll.
<!-- Toolbars -->
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background_1"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/avatar_image"
android:layout_width="@dimen/circular_image_avatar"
android:layout_height="@dimen/circular_image_avatar"
android:gravity="center"
android:scaleType="centerCrop"
android:src="@drawable/ic_placerholder"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:transitionName="image_toolbar"/>
<TextView
android:id="@+id/profile_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name title"
android:textAlignment="center"
android:layout_marginTop="@dimen/item_padding_top_bottom"
android:gravity="center"
style="@style/titleText_toolbar"
android:layout_below="@+id/avatar_image"
android:transitionName="title_toolbar"/>
<TextView
android:id="@+id/profile_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textAlignment="center"
android:gravity="center"
style="@style/captionText_toolbar"
android:layout_below="@+id/profile_title" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin">
<!-- avatar image and title, subtitle -->
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Please help me
android android-layout toolbar material-design android-collapsingtoolbarlayout
android android-layout toolbar material-design android-collapsingtoolbarlayout
edited Jul 13 '15 at 14:05
Joaquin Iurchuk
4,07012954
4,07012954
asked Jul 12 '15 at 16:12
tonilopezmrtonilopezmr
193127
193127
What code have you tried? What problems are you running into? Describe it more and we will (probably) help.
– Tristan Wiley
Jul 12 '15 at 16:14
i.imgur.com/Yj7pe5Y.jpg i.imgur.com/AUVokgc.jpg i.imgur.com/dqWq3Fp.jpg Sorry I don't have 10 reputation for post images :(
– tonilopezmr
Jul 12 '15 at 16:20
The code is irrelevant in this case, I want know how to do it
– tonilopezmr
Jul 12 '15 at 16:45
hi @tonilopezmr could you post how you achieved this?
– Hardik Amal
Jun 2 '16 at 9:31
@HardikAmal check out this github.com/saulmm/CoordinatorBehaviorExample
– tonilopezmr
Jun 9 '16 at 11:35
add a comment |
What code have you tried? What problems are you running into? Describe it more and we will (probably) help.
– Tristan Wiley
Jul 12 '15 at 16:14
i.imgur.com/Yj7pe5Y.jpg i.imgur.com/AUVokgc.jpg i.imgur.com/dqWq3Fp.jpg Sorry I don't have 10 reputation for post images :(
– tonilopezmr
Jul 12 '15 at 16:20
The code is irrelevant in this case, I want know how to do it
– tonilopezmr
Jul 12 '15 at 16:45
hi @tonilopezmr could you post how you achieved this?
– Hardik Amal
Jun 2 '16 at 9:31
@HardikAmal check out this github.com/saulmm/CoordinatorBehaviorExample
– tonilopezmr
Jun 9 '16 at 11:35
What code have you tried? What problems are you running into? Describe it more and we will (probably) help.
– Tristan Wiley
Jul 12 '15 at 16:14
What code have you tried? What problems are you running into? Describe it more and we will (probably) help.
– Tristan Wiley
Jul 12 '15 at 16:14
i.imgur.com/Yj7pe5Y.jpg i.imgur.com/AUVokgc.jpg i.imgur.com/dqWq3Fp.jpg Sorry I don't have 10 reputation for post images :(
– tonilopezmr
Jul 12 '15 at 16:20
i.imgur.com/Yj7pe5Y.jpg i.imgur.com/AUVokgc.jpg i.imgur.com/dqWq3Fp.jpg Sorry I don't have 10 reputation for post images :(
– tonilopezmr
Jul 12 '15 at 16:20
The code is irrelevant in this case, I want know how to do it
– tonilopezmr
Jul 12 '15 at 16:45
The code is irrelevant in this case, I want know how to do it
– tonilopezmr
Jul 12 '15 at 16:45
hi @tonilopezmr could you post how you achieved this?
– Hardik Amal
Jun 2 '16 at 9:31
hi @tonilopezmr could you post how you achieved this?
– Hardik Amal
Jun 2 '16 at 9:31
@HardikAmal check out this github.com/saulmm/CoordinatorBehaviorExample
– tonilopezmr
Jun 9 '16 at 11:35
@HardikAmal check out this github.com/saulmm/CoordinatorBehaviorExample
– tonilopezmr
Jun 9 '16 at 11:35
add a comment |
2 Answers
2
active
oldest
votes
smooth-app-bar-layout
see Example
Installation
compile "me.henrytao:smooth-app-bar-layout:<latest-version>"
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
add a comment |
You can also view my example with animated avatar and animated text
CollapsingAvatarToolbarSample
Read my post on Medium
So lets me to explaine how it works. I created custom view implemented AppBarLayout.OnOffsetChangedListener. Inside HeadCollapsing Custom View i founded text and image view in AppBarLayout.
class HeadCollapsing(context: Context, attrs: AttributeSet?) :
FrameLayout(context, attrs), AppBarLayout.OnOffsetChangedListener {
private fun findViews() {
appBarLayout = findParentAppBarLayout()
avatarContainerView = findViewById(R.id.imgb_avatar_wrap)
titleToolbarText = findViewById<AppCompatTextView>(id)
}
private fun findParentAppBarLayout(): AppBarLayout {
val parent = this.parent
return parent as? AppBarLayout ?: if (parent.parent is AppBarLayout) {
parent.parent as AppBarLayout
} else {
throw IllegalStateException("Must be inside an AppBarLayout")
}
}
...
override fun onOffsetChanged(appBarLayout: AppBarLayout, offset:Int) {
...
//Calculate expanded percentage
val expandedPercentage = 1 - -offset / maxOffset
updateViews(expandedPercentage)
}
}
Then change views via calculated percentage. For example, how text
view changing:
when {
inversePercentage < ABROAD -> {
titleToolbarText?.visibility = View.VISIBLE
titleTolbarTextSingle?.visibility = View.INVISIBLE
}
inversePercentage > ABROAD -> {
titleToolbarText?.visibility = View.INVISIBLE
titleTolbarTextSingle?.visibility = View.VISIBLE
titleTolbarTextSingle?.let {
animateShowText(it)
}
}
}
To detect when need image collapse animate created Pair object
private var cashCollapseState: kotlin.Pair<Int, Int>? = null
with states: TO_EXPANDED_STATE, TO_COLLAPSED_STATE, WAIT_FOR_SWITCH, SWITCHED
companion object {
const val ABROAD = 0.95f
const val TO_EXPANDED_STATE = 0
const val TO_COLLAPSED_STATE = 1
const val WAIT_FOR_SWITCH = 0
const val SWITCHED = 1
}
then cretaed animation for avatar swith state:
when {
cashCollapseState != null && cashCollapseState != state -> {
when (state.first) {
TO_EXPANDED_STATE -> {
// do calculates
}
TO_COLLAPSED_STATE -> {
ValueAnimator.ofFloat(avatarContainerView.translationX, translationX).apply {
addUpdateListener {
avatarContainerView.translationX = it.animatedValue as Float
}
duration = 350
(state.first == TO_COLLAPSED_STATE).apply {
if (this) interpolator = LinearInterpolator()
}
start()
}
//SWITCH STATE CASE
cashCollapseState = kotlin.Pair(state.first, SWITCHED)
}
else -> {
cashCollapseState = kotlin.Pair(state.first, WAIT_FOR_SWITCH)
}
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31369842%2fcollapsing-toolbar-layout-with-logo-title-subtitle-in-toolbar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
smooth-app-bar-layout
see Example
Installation
compile "me.henrytao:smooth-app-bar-layout:<latest-version>"
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
add a comment |
smooth-app-bar-layout
see Example
Installation
compile "me.henrytao:smooth-app-bar-layout:<latest-version>"
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
add a comment |
smooth-app-bar-layout
see Example
Installation
compile "me.henrytao:smooth-app-bar-layout:<latest-version>"
smooth-app-bar-layout
see Example
Installation
compile "me.henrytao:smooth-app-bar-layout:<latest-version>"
answered Mar 15 '16 at 12:18
Mansukh AhirMansukh Ahir
2,10322548
2,10322548
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
add a comment |
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
is this still relevant? I see it is deprecated.
– Tanasis
Jan 4 at 11:51
add a comment |
You can also view my example with animated avatar and animated text
CollapsingAvatarToolbarSample
Read my post on Medium
So lets me to explaine how it works. I created custom view implemented AppBarLayout.OnOffsetChangedListener. Inside HeadCollapsing Custom View i founded text and image view in AppBarLayout.
class HeadCollapsing(context: Context, attrs: AttributeSet?) :
FrameLayout(context, attrs), AppBarLayout.OnOffsetChangedListener {
private fun findViews() {
appBarLayout = findParentAppBarLayout()
avatarContainerView = findViewById(R.id.imgb_avatar_wrap)
titleToolbarText = findViewById<AppCompatTextView>(id)
}
private fun findParentAppBarLayout(): AppBarLayout {
val parent = this.parent
return parent as? AppBarLayout ?: if (parent.parent is AppBarLayout) {
parent.parent as AppBarLayout
} else {
throw IllegalStateException("Must be inside an AppBarLayout")
}
}
...
override fun onOffsetChanged(appBarLayout: AppBarLayout, offset:Int) {
...
//Calculate expanded percentage
val expandedPercentage = 1 - -offset / maxOffset
updateViews(expandedPercentage)
}
}
Then change views via calculated percentage. For example, how text
view changing:
when {
inversePercentage < ABROAD -> {
titleToolbarText?.visibility = View.VISIBLE
titleTolbarTextSingle?.visibility = View.INVISIBLE
}
inversePercentage > ABROAD -> {
titleToolbarText?.visibility = View.INVISIBLE
titleTolbarTextSingle?.visibility = View.VISIBLE
titleTolbarTextSingle?.let {
animateShowText(it)
}
}
}
To detect when need image collapse animate created Pair object
private var cashCollapseState: kotlin.Pair<Int, Int>? = null
with states: TO_EXPANDED_STATE, TO_COLLAPSED_STATE, WAIT_FOR_SWITCH, SWITCHED
companion object {
const val ABROAD = 0.95f
const val TO_EXPANDED_STATE = 0
const val TO_COLLAPSED_STATE = 1
const val WAIT_FOR_SWITCH = 0
const val SWITCHED = 1
}
then cretaed animation for avatar swith state:
when {
cashCollapseState != null && cashCollapseState != state -> {
when (state.first) {
TO_EXPANDED_STATE -> {
// do calculates
}
TO_COLLAPSED_STATE -> {
ValueAnimator.ofFloat(avatarContainerView.translationX, translationX).apply {
addUpdateListener {
avatarContainerView.translationX = it.animatedValue as Float
}
duration = 350
(state.first == TO_COLLAPSED_STATE).apply {
if (this) interpolator = LinearInterpolator()
}
start()
}
//SWITCH STATE CASE
cashCollapseState = kotlin.Pair(state.first, SWITCHED)
}
else -> {
cashCollapseState = kotlin.Pair(state.first, WAIT_FOR_SWITCH)
}
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
add a comment |
You can also view my example with animated avatar and animated text
CollapsingAvatarToolbarSample
Read my post on Medium
So lets me to explaine how it works. I created custom view implemented AppBarLayout.OnOffsetChangedListener. Inside HeadCollapsing Custom View i founded text and image view in AppBarLayout.
class HeadCollapsing(context: Context, attrs: AttributeSet?) :
FrameLayout(context, attrs), AppBarLayout.OnOffsetChangedListener {
private fun findViews() {
appBarLayout = findParentAppBarLayout()
avatarContainerView = findViewById(R.id.imgb_avatar_wrap)
titleToolbarText = findViewById<AppCompatTextView>(id)
}
private fun findParentAppBarLayout(): AppBarLayout {
val parent = this.parent
return parent as? AppBarLayout ?: if (parent.parent is AppBarLayout) {
parent.parent as AppBarLayout
} else {
throw IllegalStateException("Must be inside an AppBarLayout")
}
}
...
override fun onOffsetChanged(appBarLayout: AppBarLayout, offset:Int) {
...
//Calculate expanded percentage
val expandedPercentage = 1 - -offset / maxOffset
updateViews(expandedPercentage)
}
}
Then change views via calculated percentage. For example, how text
view changing:
when {
inversePercentage < ABROAD -> {
titleToolbarText?.visibility = View.VISIBLE
titleTolbarTextSingle?.visibility = View.INVISIBLE
}
inversePercentage > ABROAD -> {
titleToolbarText?.visibility = View.INVISIBLE
titleTolbarTextSingle?.visibility = View.VISIBLE
titleTolbarTextSingle?.let {
animateShowText(it)
}
}
}
To detect when need image collapse animate created Pair object
private var cashCollapseState: kotlin.Pair<Int, Int>? = null
with states: TO_EXPANDED_STATE, TO_COLLAPSED_STATE, WAIT_FOR_SWITCH, SWITCHED
companion object {
const val ABROAD = 0.95f
const val TO_EXPANDED_STATE = 0
const val TO_COLLAPSED_STATE = 1
const val WAIT_FOR_SWITCH = 0
const val SWITCHED = 1
}
then cretaed animation for avatar swith state:
when {
cashCollapseState != null && cashCollapseState != state -> {
when (state.first) {
TO_EXPANDED_STATE -> {
// do calculates
}
TO_COLLAPSED_STATE -> {
ValueAnimator.ofFloat(avatarContainerView.translationX, translationX).apply {
addUpdateListener {
avatarContainerView.translationX = it.animatedValue as Float
}
duration = 350
(state.first == TO_COLLAPSED_STATE).apply {
if (this) interpolator = LinearInterpolator()
}
start()
}
//SWITCH STATE CASE
cashCollapseState = kotlin.Pair(state.first, SWITCHED)
}
else -> {
cashCollapseState = kotlin.Pair(state.first, WAIT_FOR_SWITCH)
}
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
add a comment |
You can also view my example with animated avatar and animated text
CollapsingAvatarToolbarSample
Read my post on Medium
So lets me to explaine how it works. I created custom view implemented AppBarLayout.OnOffsetChangedListener. Inside HeadCollapsing Custom View i founded text and image view in AppBarLayout.
class HeadCollapsing(context: Context, attrs: AttributeSet?) :
FrameLayout(context, attrs), AppBarLayout.OnOffsetChangedListener {
private fun findViews() {
appBarLayout = findParentAppBarLayout()
avatarContainerView = findViewById(R.id.imgb_avatar_wrap)
titleToolbarText = findViewById<AppCompatTextView>(id)
}
private fun findParentAppBarLayout(): AppBarLayout {
val parent = this.parent
return parent as? AppBarLayout ?: if (parent.parent is AppBarLayout) {
parent.parent as AppBarLayout
} else {
throw IllegalStateException("Must be inside an AppBarLayout")
}
}
...
override fun onOffsetChanged(appBarLayout: AppBarLayout, offset:Int) {
...
//Calculate expanded percentage
val expandedPercentage = 1 - -offset / maxOffset
updateViews(expandedPercentage)
}
}
Then change views via calculated percentage. For example, how text
view changing:
when {
inversePercentage < ABROAD -> {
titleToolbarText?.visibility = View.VISIBLE
titleTolbarTextSingle?.visibility = View.INVISIBLE
}
inversePercentage > ABROAD -> {
titleToolbarText?.visibility = View.INVISIBLE
titleTolbarTextSingle?.visibility = View.VISIBLE
titleTolbarTextSingle?.let {
animateShowText(it)
}
}
}
To detect when need image collapse animate created Pair object
private var cashCollapseState: kotlin.Pair<Int, Int>? = null
with states: TO_EXPANDED_STATE, TO_COLLAPSED_STATE, WAIT_FOR_SWITCH, SWITCHED
companion object {
const val ABROAD = 0.95f
const val TO_EXPANDED_STATE = 0
const val TO_COLLAPSED_STATE = 1
const val WAIT_FOR_SWITCH = 0
const val SWITCHED = 1
}
then cretaed animation for avatar swith state:
when {
cashCollapseState != null && cashCollapseState != state -> {
when (state.first) {
TO_EXPANDED_STATE -> {
// do calculates
}
TO_COLLAPSED_STATE -> {
ValueAnimator.ofFloat(avatarContainerView.translationX, translationX).apply {
addUpdateListener {
avatarContainerView.translationX = it.animatedValue as Float
}
duration = 350
(state.first == TO_COLLAPSED_STATE).apply {
if (this) interpolator = LinearInterpolator()
}
start()
}
//SWITCH STATE CASE
cashCollapseState = kotlin.Pair(state.first, SWITCHED)
}
else -> {
cashCollapseState = kotlin.Pair(state.first, WAIT_FOR_SWITCH)
}
You can also view my example with animated avatar and animated text
CollapsingAvatarToolbarSample
Read my post on Medium
So lets me to explaine how it works. I created custom view implemented AppBarLayout.OnOffsetChangedListener. Inside HeadCollapsing Custom View i founded text and image view in AppBarLayout.
class HeadCollapsing(context: Context, attrs: AttributeSet?) :
FrameLayout(context, attrs), AppBarLayout.OnOffsetChangedListener {
private fun findViews() {
appBarLayout = findParentAppBarLayout()
avatarContainerView = findViewById(R.id.imgb_avatar_wrap)
titleToolbarText = findViewById<AppCompatTextView>(id)
}
private fun findParentAppBarLayout(): AppBarLayout {
val parent = this.parent
return parent as? AppBarLayout ?: if (parent.parent is AppBarLayout) {
parent.parent as AppBarLayout
} else {
throw IllegalStateException("Must be inside an AppBarLayout")
}
}
...
override fun onOffsetChanged(appBarLayout: AppBarLayout, offset:Int) {
...
//Calculate expanded percentage
val expandedPercentage = 1 - -offset / maxOffset
updateViews(expandedPercentage)
}
}
Then change views via calculated percentage. For example, how text
view changing:
when {
inversePercentage < ABROAD -> {
titleToolbarText?.visibility = View.VISIBLE
titleTolbarTextSingle?.visibility = View.INVISIBLE
}
inversePercentage > ABROAD -> {
titleToolbarText?.visibility = View.INVISIBLE
titleTolbarTextSingle?.visibility = View.VISIBLE
titleTolbarTextSingle?.let {
animateShowText(it)
}
}
}
To detect when need image collapse animate created Pair object
private var cashCollapseState: kotlin.Pair<Int, Int>? = null
with states: TO_EXPANDED_STATE, TO_COLLAPSED_STATE, WAIT_FOR_SWITCH, SWITCHED
companion object {
const val ABROAD = 0.95f
const val TO_EXPANDED_STATE = 0
const val TO_COLLAPSED_STATE = 1
const val WAIT_FOR_SWITCH = 0
const val SWITCHED = 1
}
then cretaed animation for avatar swith state:
when {
cashCollapseState != null && cashCollapseState != state -> {
when (state.first) {
TO_EXPANDED_STATE -> {
// do calculates
}
TO_COLLAPSED_STATE -> {
ValueAnimator.ofFloat(avatarContainerView.translationX, translationX).apply {
addUpdateListener {
avatarContainerView.translationX = it.animatedValue as Float
}
duration = 350
(state.first == TO_COLLAPSED_STATE).apply {
if (this) interpolator = LinearInterpolator()
}
start()
}
//SWITCH STATE CASE
cashCollapseState = kotlin.Pair(state.first, SWITCHED)
}
else -> {
cashCollapseState = kotlin.Pair(state.first, WAIT_FOR_SWITCH)
}
edited Dec 28 '18 at 21:26
answered Dec 28 '18 at 14:18
Serg BurlakaSerg Burlaka
608716
608716
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
add a comment |
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Gahan
Dec 28 '18 at 19:15
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
@Gahan done adding some describe
– Serg Burlaka
Dec 28 '18 at 19:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31369842%2fcollapsing-toolbar-layout-with-logo-title-subtitle-in-toolbar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What code have you tried? What problems are you running into? Describe it more and we will (probably) help.
– Tristan Wiley
Jul 12 '15 at 16:14
i.imgur.com/Yj7pe5Y.jpg i.imgur.com/AUVokgc.jpg i.imgur.com/dqWq3Fp.jpg Sorry I don't have 10 reputation for post images :(
– tonilopezmr
Jul 12 '15 at 16:20
The code is irrelevant in this case, I want know how to do it
– tonilopezmr
Jul 12 '15 at 16:45
hi @tonilopezmr could you post how you achieved this?
– Hardik Amal
Jun 2 '16 at 9:31
@HardikAmal check out this github.com/saulmm/CoordinatorBehaviorExample
– tonilopezmr
Jun 9 '16 at 11:35