当我在自定义的 MotionLayout 中滚动时在 textview 中调整大小
Resize in textview when I scroll in customized MotionLayout
我在 Github 中有以下项目:https://github.com/AliRezaeiii/TMDb-Paging
这是我的 person_header 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="person"
type="com.sample.android.tmdb.ui.person.PersonWrapper" />
</data>
<com.sample.android.tmdb.widget.CollapsibleToolbar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?attr/actionBarSize"
app:layoutDescription="@xml/scene_person_header"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
tools:background="?attr/colorPrimary"
tools:maxHeight="320dp">
<ImageView
android:id="@+id/image_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:imageUrl="@{@string/base_backdrop_path(person.backdropPath)}"
app:layout_constraintVertical_bias="0.38"
tools:ignore="ContentDescription" />
<View
android:id="@+id/icon_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/window_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline" />
<ImageView
android:id="@+id/tileable_edge"
android:layout_width="match_parent"
android:layout_height="30px"
android:scaleType="fitXY"
android:src="@drawable/tileable_edge"
android:tint="@color/window_background"
app:layout_constraintBottom_toTopOf="@id/icon_background"
tools:ignore="PxUsage,contentDescription" />
<FrameLayout
android:id="@+id/back_frame"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/transparent"
android:paddingStart="@dimen/padding_micro"
tools:ignore="RtlSymmetry">
<ImageButton
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?android:selectableItemBackgroundBorderless"
android:src="@drawable/ic_arrow_back_padded"
android:transitionName="@string/transition_search_back"
tools:ignore="contentDescription" />
</FrameLayout>
<TextView
android:id="@+id/name"
android:layout_width="162dp"
android:layout_height="41dp"
android:text="@{person.personName}"
app:autoSizeTextType="uniform"
tools:text="Ali Rezaei" />
<RelativeLayout
android:id="@+id/icon_layout"
android:layout_width="0dp"
android:layout_height="0dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/icon"
android:layout_width="120dp"
android:layout_height="120dp"
app:civ_border_color="@android:color/white"
app:civ_border_width="2dp"
app:profileUrl="@{person.profilePath}"
tools:src="@drawable/ic_error_outline_black_36dp" />
</RelativeLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.67" />
</com.sample.android.tmdb.widget.CollapsibleToolbar>
</layout>
CollapsibleToolbar 正在扩展 MotionLayout:
class CollapsibleToolbar @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener {
override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!!
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
(parent as? AppBarLayout)?.addOnOffsetChangedListener(this)
}
}
这里是 scene_person_header
xml 文件:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="1000"
motion:interpolator="linear">
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/image_background"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.38" />
<Constraint
android:id="@id/icon_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/guideline" />
<Constraint
android:id="@id/name"
android:layout_width="162dp"
android:layout_height="41dp"
motion:autoSizeTextType="uniform"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintStart_toStartOf="parent" />
<Constraint
android:id="@id/icon_layout"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
motion:layout_constraintBottom_toTopOf="@+id/name"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintVertical_bias="0.24000001"
motion:layout_constraintVertical_chainStyle="packed" />
<Constraint
android:id="@id/back_frame"
android:layout_width="72dp"
android:layout_height="?attr/actionBarSize"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/image_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="invisible"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.38" />
<Constraint
android:id="@id/icon_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?attr/colorPrimary"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/guideline" />
<Constraint
android:id="@id/name"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginBottom="14dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toEndOf="@+id/back_frame" />
<Constraint
android:id="@id/icon_layout"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent" />
<Constraint
android:id="@id/back_frame"
android:layout_width="72dp"
android:layout_height="?attr/actionBarSize"
motion:layout_constraintBottom_toBottomOf="parent" />
</ConstraintSet>
</Transition>
</MotionScene>
当我启动 PersonActivity 时,角色名称如下图所示:
当我开始在 PersonActivity 中滚动时,角色名称会调整大小并显示为下图:
我应该怎么做才能让 name
的初始大小作为 motionLayout 开始滚动的初始大小?我应该在此处进行任何更改吗:
<TextView
android:id="@+id/name"
android:layout_width="162dp"
android:layout_height="41dp"
android:text="@{person.personName}"
app:autoSizeTextType="uniform"
tools:text="Ali Rezaei" />
您可以在以下位置找到问题跟踪:https://issuetracker.google.com/issues/155215198
我在 Github 中有以下项目:https://github.com/AliRezaeiii/TMDb-Paging
这是我的 person_header 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="person"
type="com.sample.android.tmdb.ui.person.PersonWrapper" />
</data>
<com.sample.android.tmdb.widget.CollapsibleToolbar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?attr/actionBarSize"
app:layoutDescription="@xml/scene_person_header"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
tools:background="?attr/colorPrimary"
tools:maxHeight="320dp">
<ImageView
android:id="@+id/image_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:imageUrl="@{@string/base_backdrop_path(person.backdropPath)}"
app:layout_constraintVertical_bias="0.38"
tools:ignore="ContentDescription" />
<View
android:id="@+id/icon_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/window_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline" />
<ImageView
android:id="@+id/tileable_edge"
android:layout_width="match_parent"
android:layout_height="30px"
android:scaleType="fitXY"
android:src="@drawable/tileable_edge"
android:tint="@color/window_background"
app:layout_constraintBottom_toTopOf="@id/icon_background"
tools:ignore="PxUsage,contentDescription" />
<FrameLayout
android:id="@+id/back_frame"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/transparent"
android:paddingStart="@dimen/padding_micro"
tools:ignore="RtlSymmetry">
<ImageButton
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?android:selectableItemBackgroundBorderless"
android:src="@drawable/ic_arrow_back_padded"
android:transitionName="@string/transition_search_back"
tools:ignore="contentDescription" />
</FrameLayout>
<TextView
android:id="@+id/name"
android:layout_width="162dp"
android:layout_height="41dp"
android:text="@{person.personName}"
app:autoSizeTextType="uniform"
tools:text="Ali Rezaei" />
<RelativeLayout
android:id="@+id/icon_layout"
android:layout_width="0dp"
android:layout_height="0dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/icon"
android:layout_width="120dp"
android:layout_height="120dp"
app:civ_border_color="@android:color/white"
app:civ_border_width="2dp"
app:profileUrl="@{person.profilePath}"
tools:src="@drawable/ic_error_outline_black_36dp" />
</RelativeLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.67" />
</com.sample.android.tmdb.widget.CollapsibleToolbar>
</layout>
CollapsibleToolbar 正在扩展 MotionLayout:
class CollapsibleToolbar @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr), AppBarLayout.OnOffsetChangedListener {
override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {
progress = -verticalOffset / appBarLayout?.totalScrollRange?.toFloat()!!
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
(parent as? AppBarLayout)?.addOnOffsetChangedListener(this)
}
}
这里是 scene_person_header
xml 文件:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="1000"
motion:interpolator="linear">
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/image_background"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.38" />
<Constraint
android:id="@id/icon_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/window_background"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/guideline" />
<Constraint
android:id="@id/name"
android:layout_width="162dp"
android:layout_height="41dp"
motion:autoSizeTextType="uniform"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintStart_toStartOf="parent" />
<Constraint
android:id="@id/icon_layout"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
motion:layout_constraintBottom_toTopOf="@+id/name"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintHorizontal_bias="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintVertical_bias="0.24000001"
motion:layout_constraintVertical_chainStyle="packed" />
<Constraint
android:id="@id/back_frame"
android:layout_width="72dp"
android:layout_height="?attr/actionBarSize"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/image_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="invisible"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.38" />
<Constraint
android:id="@id/icon_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?attr/colorPrimary"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/guideline" />
<Constraint
android:id="@id/name"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginBottom="14dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toEndOf="@+id/back_frame" />
<Constraint
android:id="@id/icon_layout"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent" />
<Constraint
android:id="@id/back_frame"
android:layout_width="72dp"
android:layout_height="?attr/actionBarSize"
motion:layout_constraintBottom_toBottomOf="parent" />
</ConstraintSet>
</Transition>
</MotionScene>
当我启动 PersonActivity 时,角色名称如下图所示:
当我开始在 PersonActivity 中滚动时,角色名称会调整大小并显示为下图:
我应该怎么做才能让 name
的初始大小作为 motionLayout 开始滚动的初始大小?我应该在此处进行任何更改吗:
<TextView
android:id="@+id/name"
android:layout_width="162dp"
android:layout_height="41dp"
android:text="@{person.personName}"
app:autoSizeTextType="uniform"
tools:text="Ali Rezaei" />
您可以在以下位置找到问题跟踪:https://issuetracker.google.com/issues/155215198