Fix scaling of breadcrumbs for very large text sizes

Breadcrumbs component previously had fixed height which made it cut off
text when it is changed to largest sizes in settings.

This changes breadcrumbs to have dynamic height, based on contents,
with just the minimum height based on previously fixed size.

The previously fixed height was also put on items as minimum height,
to ensure consistent behavior with smaller fonts too, but this will
have effect only on very small font sizes (not realistic). Centering
of text was added for that reason too. It can be removed if needed,
since it is needed only for unrealistically small font sizes.
This commit is contained in:
Ensar Sarajčić 2023-07-05 13:10:11 +02:00
parent 1c82e70f86
commit ad9322992f
4 changed files with 8 additions and 16 deletions

View file

@ -14,7 +14,7 @@ import androidx.core.view.ViewCompat
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.models.FileDirItem
import kotlinx.android.synthetic.main.item_breadcrumb.view.*
import kotlinx.android.synthetic.main.item_breadcrumb.view.breadcrumb_text
class Breadcrumbs(context: Context, attrs: AttributeSet) : HorizontalScrollView(context, attrs) {
private val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
@ -101,19 +101,6 @@ class Breadcrumbs(context: Context, attrs: AttributeSet) : HorizontalScrollView(
recomputeStickyRootLocation(left)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
var heightMeasureSpec = heightMeasureSpec
if (heightMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.AT_MOST) {
var height = context.resources.getDimensionPixelSize(R.dimen.breadcrumbs_layout_height)
if (heightMode == MeasureSpec.AT_MOST) {
height = height.coerceAtMost(MeasureSpec.getSize(heightMeasureSpec))
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
private fun scrollToSelectedItem() {
if (isLayoutDirty) {
isScrollToSelectedItemPending = true

View file

@ -20,6 +20,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:minHeight="@dimen/breadcrumbs_layout_height"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"

View file

@ -2,7 +2,9 @@
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/breadcrumb_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/breadcrumbs_layout_height"
android:paddingLeft="@dimen/small_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingRight="@dimen/small_margin"

View file

@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/tiny_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/breadcrumb_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="@dimen/breadcrumbs_layout_height"
android:paddingLeft="@dimen/small_margin"
android:paddingTop="@dimen/medium_margin"
android:paddingRight="@dimen/small_margin"