Android中的SharedElementTransition

时间:2016-06-24 10:33:21

标签: java android xml android-layout material-design

我正在尝试从RecyclerView中的项目执行SharedElementTransition到该元素的DetailedActivity,但是没有显示转换,并且在按下后退按钮时,应用程序与logcat崩溃如下:

  

06-24 16:03:52.512 31808-31808 / com.example.xyzreader E / AndroidRuntime:FATAL EXCEPTION:main                                                                          处理:com.example.xyzreader,PID:31808                                                                          主题:主题:{default = overlay:system,iconPack:system,com.android.systemui = overlay:system,com.android.systemui.navbar = overlay:system}                                                                          java.lang.IllegalStateException:无法为MaxWidthLinearLayout创建图层                                                                              在android.os.MessageQueue.nativePollOnce(本机方法)                                                                              在android.os.MessageQueue.next(MessageQueue.java:323)                                                                              在android.os.Looper.loop(Looper.java:135)                                                                              在android.app.ActivityThread.main(ActivityThread.java:5471)                                                                              at java.lang.reflect.Method.invoke(Native Method)                                                                              在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                              在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

各种类和布局文件如下:

ArticleListActivity.java

                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {

                    Bundle bundle = ActivityOptions
                            .makeSceneTransitionAnimation(
                                    activity,
                                    vh.titleView,
                                    vh.titleView.getTransitionName()
                            ).toBundle();

                    Intent intent = new Intent(Intent.ACTION_VIEW, ItemsContract.Items.buildItemUri(getItemId(vh.getAdapterPosition())));

                    startActivity(intent, bundle);
                } else {

                    startActivity(new Intent(Intent.ACTION_VIEW,
                            ItemsContract.Items.buildItemUri(getItemId(vh.getAdapterPosition()))));
                }

list_item_article.xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
android:elevation="2dp"
>

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

    <ImageView
        android:id="@+id/thumbnail"
        android:background="@color/my_image_background_color"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:transitionName="@string/shared_element_transition"
        android:scaleType="fitStart"
        android:adjustViewBounds="true"
        />

    <TextView
        android:id="@+id/article_title_cardview"
        style="@style/TextAppearance.AppCompat.Subhead"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:transitionName="@string/article_title"
        android:ellipsize="end"
        android:maxLines="4"
        android:paddingBottom="4dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="16dp"
        android:textColor="@color/primary_text" />


    <TextView
        android:id="@+id/author"
        style="@style/TextAppearance.AppCompat.Body1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:textColor="#6000"
        />

    <TextView
        android:id="@+id/time"
        style="@style/TextAppearance.AppCompat.Body1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:paddingBottom="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:textColor="#6000" />
</LinearLayout>

fragment_article_detail.xml

<com.example.xyzreader.ui.DrawInsetsFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/draw_insets_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.example.xyzreader.ui.ObservableScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">


        <FrameLayout
            android:id="@+id/photo_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.example.xyzreader.ui.ThreeTwoImageView
                android:id="@+id/photo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:transitionName="@string/shared_element_transition" />


            <View
                android:layout_width="match_parent"
                android:layout_height="112dp"
                android:background="@drawable/photo_background_protection" />

        </FrameLayout>


        <com.example.xyzreader.ui.MaxWidthLinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/photo_container"
            android:layout_gravity="center_horizontal"
            android:background="#fff"
            android:elevation="4dp"
            android:maxWidth="@dimen/detail_card_max_width"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/meta_bar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginBottom="@dimen/detail_metabar_vert_padding"
                android:background="#333"
                android:orientation="vertical"
                android:paddingBottom="@dimen/detail_metabar_vert_padding"
                android:paddingLeft="@dimen/detail_inner_horiz_margin"
                android:paddingRight="@dimen/detail_inner_horiz_margin"
                android:paddingTop="@dimen/detail_metabar_vert_padding">

                <TextView
                    android:id="@+id/article_title"
                    style="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="sans-serif-condensed"
                    android:lineSpacingMultiplier="0.9"
                    android:transitionName="@string/article_title"
                    android:paddingBottom="@dimen/detail_metabar_title_bottom_padding"
                    android:textColor="#fff"
                    android:textSize="@dimen/detail_title_text_size"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/article_byline"
                    style="?android:attr/textAppearanceSmall"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#8fff" />
            </LinearLayout>

            <TextView
                android:id="@+id/article_body"
                style="?android:attr/textAppearanceMedium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/detail_inner_horiz_margin"
                android:layout_marginRight="@dimen/detail_inner_horiz_margin"
                android:lineSpacingMultiplier="@fraction/detail_body_line_spacing_multiplier"
                android:paddingBottom="@dimen/detail_body_bottom_margin"
                android:textColor="@color/primary_text"
                android:textColorLink="@color/accent"
                android:textSize="@dimen/detail_body_text_size" />

        </com.example.xyzreader.ui.MaxWidthLinearLayout>
    </RelativeLayout>


</com.example.xyzreader.ui.ObservableScrollView>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/share_fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="@dimen/fab_margin"
    android:layout_marginEnd="@dimen/fab_margin"
    android:layout_marginRight="@dimen/fab_margin"
    android:contentDescription="@string/action_share"
    android:padding="4dp"
    android:src="@drawable/ic_share"
    app:elevation="@dimen/fab_elevation"
    app:fabSize="normal" />

1 个答案:

答案 0 :(得分:0)

你可以发布完整的堆栈跟踪吗?我认为你发布的堆栈跟踪应该有一些东西。

我有类似的问题,我通过向接收xml添加以下属性来解决它:

android:transitionGroup="true"

因为传入的视图太大而在我的情况下崩溃。