This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
binding.appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> | |
// By updating the LayoutParams, we trigger the offset change listener, which then results in a somewhat infinite loop. | |
// This flag makes sure that we discard the next callback after updating the layout. | |
if (verticalOffset == lastOffset) { | |
return@OnOffsetChangedListener | |
} | |
val offsetPercentage = verticalOffset / -maxOffset // 0 is fully expanded, 1 is fully collapsed | |
val interpolatedPercentage = interpolator.getInterpolation(offsetPercentage) | |
val baseWidth = expandedTextWidth - (expandedTextWidth - collapsedTextWidth) * interpolatedPercentage | |
val marginExtra = expandedMargin - (expandedMargin - collapsedMargin) * offsetPercentage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal fun disallowToolbarExpand() { | |
// Taken from: https://stackoverflow.com/a/49218710/1395437 | |
binding.appBar.setExpanded(false, false) | |
ViewCompat.setNestedScrollingEnabled(binding.content, false) | |
val params = binding.appBar.layoutParams as CoordinatorLayout.LayoutParams | |
if (params.behavior == null) { | |
params.behavior = AppBarLayout.Behavior() | |
} | |
val behaviour = params.behavior as AppBarLayout.Behavior | |
behaviour.setDragCallback(object : AppBarLayout.Behavior.DragCallback() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.SuppressLint | |
import android.content.Context | |
import android.text.Layout | |
import android.text.Spannable | |
import android.text.SpannableStringBuilder | |
import android.text.Spanned | |
import android.text.StaticLayout | |
import android.text.TextPaint | |
import android.text.method.LinkMovementMethod | |
import android.text.style.ClickableSpan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<com.google.android.material.appbar.CollapsingToolbarLayout | |
android:id="@+id/collapsing_toolbar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
app:expandedTitleMarginStart="@dimen/genre_clickable_title_left_margin" | |
app:expandedTitleMarginBottom="@dimen/genre_clickable_title_bottom_margin" | |
app:expandedTitleMarginTop="0dp" | |
app:collapsedTitleGravity="center" | |
android:background="@color/background" | |
app:collapsedTitleTextAppearance="@style/AppTheme.CollapsingToolbarTitle.Collapsed" |
OlderNewer