Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout shared element transition issue

Here we go: two Activities with a shared element transition (Button). The second Activity has a TextInputLayout with a hint:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:focusable="true"
              android:focusableInTouchMode="true"
              android:gravity="center_horizontal"
              android:orientation="vertical">

    <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="GO"
            android:transitionName="test"/>

    <android.support.design.widget.TextInputLayout android:layout_width="match_parent"
                                                   android:layout_height="wrap_content"
                                                   android:hint="WTF?!">
        <android.support.design.widget.TextInputEditText android:layout_width="match_parent"
                                                         android:layout_height="wrap_content"/>
    </android.support.design.widget.TextInputLayout>
</LinearLayout>   

The enter transition of the second Activity is delayed for clarifying the problem: The hint of the TextInputLayout ignores the transition animation and displayed immediately after the transition is started. At the end of the animation you can see the correctly animated EditText background (horizontal line) below the hint. Is this a bug or am I missing something? Here is the second Activity:

public class SecondActivity extends AppCompatActivity {

    public static void launch(Activity activity, View sharedElement) {
        Intent intent = new Intent(activity, SecondActivity.class);

        ActivityOptionsCompat options = ActivityOptionsCompat.
                makeSceneTransitionAnimation(activity, sharedElement, "test");
        activity.startActivity(intent, options.toBundle());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setEnterTransition(new Slide().setDuration(5000));
        }
    }
}

EDIT: This bug can be "fixed" by adding a background the the second Activity's layout.

without backgroundwith background

like image 824
artkoenig Avatar asked Sep 20 '17 12:09

artkoenig


1 Answers

for API 21+

android:transitionGroup="true"

Add this line in TextInputLayout. It would fix it. Or if you have a few TextInputLayout then add that line to their container.

like image 177
Jurij Pitulja Avatar answered Nov 15 '22 15:11

Jurij Pitulja