代码之家  ›  专栏  ›  技术社区  ›  Parth Anjaria

共享元素转换在片段中不起作用

  •  0
  • Parth Anjaria  · 技术社区  · 7 年前

    需要一个动画。

    片段1中有一个recyclerViewholder,其行项目如下:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        xmlns:tools="http://schemas.android.com/tools">
        <LinearLayout
            android:id="@+id/badge_layout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="32dp"
            android:orientation="vertical"
    
            >
        <ImageView
            android:layout_width="64dp"
            android:layout_height="74dp"
            android:id="@+id/iv_acheivements"
            android:src="@drawable/badge_image"
            android:transitionName="@string/badge_image_fragment_transition"
            tools:ignore="UnusedAttribute"
            />
        <com.sharesmile.share.views.LBTextView
            android:layout_width="64dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:id="@+id/tv_acheivements_title"
            android:textSize="11sp"
            android:textColor="@color/black_53"
            android:layout_marginTop="13dp"
            android:text="Change Maker"
            />
        </LinearLayout>
    </LinearLayout>
    

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">
        <ImageView
            android:id="@+id/close_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_close_black_24dp"
            android:layout_gravity="right"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="3dp"
            android:visibility="invisible"
            />
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="50dp"
            android:paddingRight="50dp">
        <com.sharesmile.share.views.LBTextView
            android:id="@+id/congratulation_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/congratulations"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/clr_5d"
            android:textSize="24dp"
            />
        <com.sharesmile.share.views.LRTextView
            android:id="@+id/badge_earned_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/clr_5d"
            android:text="@string/upgraded_your_badge_txt"
            android:layout_gravity="center"
            android:textSize="14sp"
            android:layout_marginTop="5dp"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical"
            >
            <ImageView
                android:layout_width="150dp"
                android:layout_height="180dp"
                android:id="@+id/iv_badge"
                android:src="@drawable/badge_image"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"
                android:transitionName="@string/badge_image_fragment_transition"
                tools:ignore="UnusedAttribute"
                />
            <com.sharesmile.share.views.LBKTextView
                android:id="@+id/badge_title_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="24sp"
                android:textColor="@color/black_57"
                tools:text="CAPTAIN PLANET"
                android:layout_marginBottom="10dp"
                android:gravity="center"
                />
            <com.sharesmile.share.views.LRTextView
                android:id="@+id/badge_amount_raised_tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textSize="16sp"
                tools:text="Thanks for raising \u20B9 500 for our environment"
                android:textColor="@color/greyish_brown_two"
                android:layout_marginBottom="10dp"
                />
            <com.sharesmile.share.views.LRTextView
                android:id="@+id/badge_upgrade_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textSize="16sp"
                tools:text="Badge Upgrade : Raise \u20B91500 more"
                android:textColor="@color/greyish_brown_two"
                />
    
        </LinearLayout>
        <com.sharesmile.share.views.MSBButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/tell_your_friends"
            android:background="@drawable/rounded_corner"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:layout_gravity="center_horizontal"
            android:paddingTop="14dp"
            android:paddingBottom="14dp"
            android:id="@+id/btn_tell_your_friends"
            android:layout_marginBottom="20dp"
            />
        <com.sharesmile.share.views.LBTextView
            android:id="@+id/continue_tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/badge_continue"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="20dp"
            android:visibility="visible"
            />
        </LinearLayout>
    </LinearLayout>
    

    片段a中的代码是:

     FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.addSharedElement(sharedView, ViewCompat.getTransitionName(sharedView));
                if(getSupportFragmentManager().findFragmentByTag(tag)==null) {
                    fragmentTransaction.replace(getFrameLayoutId(), fragmentToBeLoaded,
                            tag);
    
                    if (addToBackStack) {
                        fragmentTransaction.addToBackStack(tag);
                    }
                    if (allowStateLoss) {
                        fragmentTransaction.commitAllowingStateLoss();
                    } else {
                        fragmentTransaction.commit();
                    }
    

    第二个片段是:

     @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                setSharedElementEnterTransition(TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move));
            }
        }
    

    导入片段:(如果这是您希望检查的内容)

    import android.support.v4.app.Fragment;
    import android.view.View;
    

    0 回复  |  直到 7 年前