从TextView到EditText的共享元素转换错误

时间:2015-10-07 11:34:19

标签: android android-transitions shared-element-transition

我尝试在TextViewEditText´ but when showing the resulting Activity the text in the EditView have been shifted up. See attached pictures. Also, clicking on the EditView`之间进行Android共享转换,转换后将文本恢复到正确的位置。

首先点击RecylcerView中的任何一行:

enter image description here

单元格视图,日期TextEdit和名称TextEdit将共享给下一个活动。单元格背景将转换为工具栏。

enter image description here

启动活动单元格布局:

<?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>

活动的结束布局:

<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>

转换代码:

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);
    }
}

0 个答案:

没有答案