Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

android - After update material:1.3.0-alpha03

After updating to androidx.fragment:fragment-testing v1.0-alpha04 or new animation stops working when scrolling in TextView. In the CoordinatorLayout.Behavior() is not called onDependentViewChanged and dependency as AppBarLayout totalScrollRange is always 0

Below is an abbreviated code for reproducing the error.

CollapsingBehavior

    class CollapsingBehavior(context: Context, attrs: AttributeSet?) :
        CoordinatorLayout.Behavior<View>() {

    private var mTargetId = 0
    private val targetTitleSize = context.resources.getDimensionPixelSize(R.dimen.text_header_18) / context.resources.displayMetrics.scaledDensity
    private var mTextSize: Float? = null

    init {
        if(attrs!=null){
            val a = context.obtainStyledAttributes(attrs, R.styleable.TicketCollapsingBehavior)
            mTargetId = a.getResourceId(R.styleable.TicketCollapsingBehavior_collapsedTicketTarget, 0)
            a.recycle()
        }
        check(mTargetId != 0) { "collapsedTicketTarget attribute not specified on view for behavior" }
    }

    override fun onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View): Boolean {
        setup(child)
        val appBarLayout = dependency as AppBarLayout
        val factor: Float = -appBarLayout.y / appBarLayout.totalScrollRange

        if (mTextSize !=null) {
            (child as TextView).setTextSize(TypedValue.COMPLEX_UNIT_SP,
                    (mTextSize!! + factor * (targetTitleSize - mTextSize!!)))
        }
        return true
    }
    private fun setup(child: View) {
        if (mTextSize == null)
            mTextSize = (child as TextView).textSize / child.resources.displayMetrics.scaledDensity
    }

    override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean = dependency is AppBarLayout[enter image description here][1]}

activity_main.xml

<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stateListAnimator="@null"
            android:background="@color/second_background">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="150dp"
                app:expandedTitleGravity="center_horizontal"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:contentInsetLeft="0dp"
                    app:contentInsetStart="0dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:layout_collapseMode="pin">

                    <Space
                        android:id="@+id/collapsed_task_target"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_scrollFlags="scroll|exitUntilCollapsed"
                        app:layout_collapseMode="pin"/>

                </androidx.appcompat.widget.Toolbar>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

        </com.google.android.material.appbar.AppBarLayout>

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:id="@+id/rv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingStart="@dimen/margin_16"
                android:paddingEnd="@dimen/margin_16"
                android:textColor="@android:color/black"
                android:textSize="@dimen/text_header_16"
                android:text="@string/large_text" />

        </androidx.core.widget.NestedScrollView>

        <TextView
            android:id="@+id/tv_title"
            android:text="I'm not work."
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_16"
            app:collapsedTicketTarget="@id/collapsed_task_target"
            app:layout_behavior="com.jz.testcollapsing.CollapsingBehavior"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>

after update library

before update library

question from:https://stackoverflow.com/questions/65851075/after-update-material1-3-0-alpha03

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...