首页 > 解决方案 > MotionLayout issue with Buttons, EditTexts and focus

问题描述

This is my third attempt to use motionLayout and I don't want to give up again because of the issues I get in my implementation.

The problem that I am now facing is that I have a card (with some editTexts and a button) and the card can be swiped up to expand. Swiping it down lets only one editText visible.

The problem is that sometimes I get very weird and breaking issues with the button and inputs, most likely problems of focus. After I swipe the card, the button cannot be pressed (or has to be press around 20-30 times to work). What's weird is that as soon as I press the button, it looks like the ripple animation inside the button just freezes. Also some inputs can no longer be clicked. If I do manage to press the button or focus on some field, most of the time (but not always), I cannot swipe the card anymore. These are some serious issues that cannot go into production. I am not doing anything with my button or inputs in code except setting a clickListener on the button, they are just in XML for the time being so it's not an issue of Kotlin code breaking them somehow.

Can anyone please tell me what I'm doing wrong and how these issues can be avoided?

Motion Layout code:

<?xml version="1.0" encoding="utf-8"?>

<Transition android:id="@+id/transitionMinimizedToFull"
        motion:constraintSetEnd="@id/full"
        motion:constraintSetStart="@id/minimized"
        motion:duration="300"
        motion:layoutDuringTransition="honorRequest"
        motion:motionInterpolator="cubic(0.4,0,0.98,0.26)">

    <OnSwipe motion:dragDirection="dragUp"
            motion:touchRegionId="@id/details" />

    <KeyFrameSet>

        <KeyAttribute android:scaleX="0.95"
                android:scaleY="0.95"
                motion:framePosition="0"
                motion:motionTarget="@+id/details" />

        <KeyAttribute android:scaleX="1.0"
                android:scaleY="1.0"
                motion:framePosition="100"
                motion:motionTarget="@+id/details" />

    </KeyFrameSet>

</Transition>

<ConstraintSet android:id="@+id/full">

    <Constraint android:id="@id/details">

        <Layout android:layout_width="match_parent"
                android:layout_height="wrap_content"
                motion:layout_constraintBottom_toBottomOf="parent"
                motion:layout_constraintEnd_toEndOf="parent"
                motion:layout_constraintStart_toStartOf="parent" />

    </Constraint>

</ConstraintSet>

<ConstraintSet android:id="@+id/minimized">

    <Constraint android:id="@id/details">

        <Layout android:layout_width="match_parent"
                android:layout_height="wrap_content"
                motion:layout_constraintEnd_toEndOf="parent"
                motion:layout_constraintStart_toStartOf="parent"
                motion:layout_constraintTop_toTopOf="@+id/guideline" />
    </Constraint>

</ConstraintSet>

标签: androidkotlinandroid-edittextandroid-motionlayout

解决方案


推荐阅读