Android - 共享元素转换使recyclerview项目变小

时间:2017-07-24 14:44:48

标签: android android-recyclerview android-glide shared-element-transition

在配置文件图像上使用共享元素转换启动配置文件活动后,RecyclerView中的项目非常小。如果我不做这个过渡,那么他们就没事了。为什么以及如何解决?

以下是效果的GIF:https://gyazo.com/82fb97f0539a2eeea1677a682a1f1d27

我的回收者onBindViewHolder:

    @Override
public void onBindViewHolder(BaseHolder<ProfileItemBinding> holder, int position) {
    ProfileItemBinding binding = holder.getBinding();
    binding.profileItemName.setText(mTitles[position]);
    binding.profileItemValue.setText(mValues.get(position));
    binding.profileItemValue.setSelected(true);
    binding.setViewModel(new ProfileItemModel(mTitles[position], mValues.get(position)));
}

如何设置图像:

    private void initProfileImage(String url) {
    supportPostponeEnterTransition();
    GlideApp.with(this)
            .load(url)
            .dontAnimate()
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    supportStartPostponedEnterTransition();
                    if (e != null) e.printStackTrace();
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                    supportStartPostponedEnterTransition();
                    return false;
                }
            })
            .into(mActivityProfileBinding.profileImage);
}

我如何开始活动:

    public void onProfileClick(View view) {
    Intent i = new Intent(view.getContext(), ProfileActivity.class);
    ActivityOptionsCompat options = ActivityOptionsCompat
            .makeSceneTransitionAnimation(((MainActivity) mContext), view, "profile_image");
    view.getContext().startActivity(i, options.toBundle());
}

我在Recycler中使用的个人资料项目:

    <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="viewModel"
            type="org.imperium.imperious.Pastebin.viewmodels.ProfileItemModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/profile_item_container"
        android:foreground="?selectableItemBackgroundBorderless"
        android:onClick="@{viewModel::onItemClick}"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/profile_item_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:alpha="0.6"
                android:padding="16dp"
                android:text="Username"
                android:textColor="@color/md_black_1000"
                android:textSize="18sp" />

            <!-- The use of "singeLine" is because Marquee will not work without it. Android bug or me sucking maybe. -->
            <TextView
                android:id="@+id/profile_item_value"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:alpha="0.6"
                android:ellipsize="marquee"
                android:gravity="end"
                android:marqueeRepeatLimit="marquee_forever"
                android:padding="16dp"
                android:singleLine="true"
                android:text="http://pastebin.com/cache/img/2/7/9/2487617.jpg"
                android:textColor="@color/md_black_1000"
                android:textSize="18sp"
                android:textStyle="bold"
                tools:ignore="Deprecated" />

        </LinearLayout>

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="@color/md_grey_300" />

    </LinearLayout>

</layout>

我的个人资料活动:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

        <variable
            name="viewModel"
            type="org.imperium.imperious.Pastebin.viewmodels.ProfileActivityModel" />
    </data>

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".activities.ProfileActivity">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/profile_image"
                    android:layout_width="match_parent"
                    android:layout_height="128dp"
                    android:layout_margin="64dp"
                    android:fitsSystemWindows="true"
                    android:onClick="@{viewModel::onImageClick}"
                    android:scaleType="centerCrop"
                    android:src="@drawable/guest"
                    android:transitionName="profile_image"
                    app:civ_border_color="@color/colorAccent"
                    app:civ_border_width="2dp"
                    app:layout_collapseMode="parallax" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/AppTheme.PopupOverlay" />

            </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>

        <!--

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/fab_margin"
            app:layout_anchor="@+id/app_bar"
            app:layout_anchorGravity="bottom|end"
            app:srcCompat="@drawable/ic_check" /> -->

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/profile_scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <include
                android:id="@+id/profile_include"
                layout="@layout/profile_layout" />

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

    </android.support.design.widget.CoordinatorLayout>

</layout>

我的个人资料布局(活动中的包含):

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:id="@+id/profile_layout_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/profile_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>
</layout>

1 个答案:

答案 0 :(得分:0)

在考虑了一下之后,我想起了我在我的LayoutManager上有动画的那种&#34;放大了&#34;所有添加的项目,这就是为什么它看起来像那样。由于某种原因,它并没有完成动画,但删除动画是一个很好的解决方案。