Shared Element transition bug from TextView to EditText

依然范特西╮ 提交于 2019-12-06 03:52:29

问题


I am trying to do an Android Shared Transtion between a TextView and a EditText´ but when showing the resulting Activity the text in theEditViewhave been shifted up. See attached pictures. Also, clicking on theEditView` after the transition will restore the text to the correct position.

First clicking any row in RecylcerView:

The cell view, the date TextEdit and the Name TextEdit are shared to the next activity. The cell background is transitioned into the toolbar.

Start activity cell layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/adapter_actionlist"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:clickable="true"
              android:focusable="true"
              android:background="?android:attr/selectableItemBackground"
              android:transitionName="@string/transition_key_action" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="72dp"
        >

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/adapter_actionList_checkBox"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="12dp"/>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="72dp"
            android:layout_marginRight="16dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxLines="2"
                android:ellipsize="end"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Large Text"
                android:id="@+id/adapter_actionlist_toplabel"
                android:paddingTop="0dp"
                android:paddingBottom="0dp"
                android:textSize="14sp"
                android:transitionName="@string/transition_key_action_name"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Medium Text"
                android:id="@+id/adapter_actionlist_bottomlabel"
                android:paddingTop="0dp"
                android:paddingBottom="0dp"
                android:autoText="false"
                android:textSize="14sp"
                android:transitionName="@string/transition_key_action_date"
                />
        </LinearLayout>

    </RelativeLayout>
</LinearLayout>

End layout for activity:

<LinearLayout
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/activity_action_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary_color"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp"
        android:elevation="4dp"
        android:fitsSystemWindows="true"
        app:navigationIcon="@drawable/abc_ic_ab_back_mtrl_am_alpha"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:transitionName="@string/transition_key_action">

            <LinearLayout
                android:id="@+id/actvity_action_focus_placeholder"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginTop="56dp"
                android:layout_marginLeft="16dp"
                android:descendantFocusability="beforeDescendants"
                android:focusableInTouchMode="true"
                android:paddingBottom="6dp">

                <EditText
                    android:id="@+id/activity_action_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Title"
                    android:layout_marginRight="16dp"
                    android:imeOptions="actionDone"
                    android:singleLine="true"
                    android:ellipsize="none"
                    android:inputType="text"
                    android:textSize="22sp"
                    android:textColor="#fff"
                    android:focusable="true"
                    android:background="@android:color/transparent"
                    android:transitionName="@string/transition_key_action_name"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Från: [Möte] (Datum)"
                    android:id="@+id/activity_action_meetingdate"
                    android:textColor="#fff"
                    android:layout_marginBottom="6dp"
                    android:layout_marginRight="16dp"
                    android:transitionName="@string/transition_key_action_date"/>

            </LinearLayout>

    </android.support.v7.widget.Toolbar>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/activity_action_swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context=".Activities.ActionActivity">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/activity_action_recyclerview"
                android:scrollbars="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:descendantFocusability="beforeDescendants"/>

    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

Transition code:

private void startActionActivity(int selectedRow, View animateFromView)
{
    Intent intent = new Intent(this, ActionActivity.class);
    Action selectedAction = mAdapter.getActionAtPosition(selectedRow);
    intent.putExtra(Constants.SELECTED_ACTION_ID_KEY, selectedAction.id);

    if (animateFromView != null) {

        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                Pair.create(animateFromView, getResources().getString(R.string.transition_key_action)),
                Pair.create(animateFromView.findViewById(R.id.adapter_actionlist_toplabel), getResources().getString(R.string.transition_key_action_name)),
                Pair.create(animateFromView.findViewById(R.id.adapter_actionlist_bottomlabel), getResources().getString(R.string.transition_key_action_date)));

        startActivity(intent, options.toBundle());
    }
    else {
        startActivity(intent);
    }
}

来源:https://stackoverflow.com/questions/32991132/shared-element-transition-bug-from-textview-to-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!