7

все! У меня есть 2 фрагмента. В одном фрагменте у меня есть небольшое изображение в карточке. В 2d-фрагменте у меня одинаковое изображение в заголовке моего макета. Я хочу сделать разделяемую переходный элемент этого образа от одного фрагмента к другому, как в этом примере http://1.bp.blogspot.com/-Vv4SxVSI2DY/VEqQxAf3PWI/AAAAAAAAA7c/mfq7XBrIGgo/s1600/activity_transitions%2B(1).gifПереход фрагмента Android с общим элементом

2d фрагмент:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#f2f4f7"> 
<CustomScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#f2f4f7"> 
    <LinearLayout 
     android:id="@+id/content_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:divider="@drawable/vertical_divider" 
     android:showDividers="middle"> 
     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <RelativeLayout 
       android:id="@+id/header_wrapper" 
       android:layout_width="match_parent" 
       android:layout_height="166.7dp"> 
       <ImageView 
        android:id="@+id/share_image" 
        android:transitionName="imageTransition" 
        android:layout_width="match_parent" 
        android:layout_height="166.7dp" 
        android:src="@drawable/friday"/> 

первый фрагмент:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:gravity="center_horizontal" 
android:layout_marginTop="56dp" 
android:background="#ff1e1e23"> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="25dp" 
    android:src="@drawable/menuicon1g"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="25dp" 
    android:gravity="center" 
    android:textColor="#fff" 
    android:textSize="22sp"/> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_gravity="center" 
    android:layout_width="200dp" 
    android:layout_height="300dp" 
    android:layout_marginTop="25dp" 
    card_view:cardCornerRadius="4dp" 
    card_view:cardBackgroundColor="#fff" 
    card_view:cardElevation="2dp"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:gravity="center_horizontal"> 
     <ImageView 
      android:id="@+id/share_image" 
      android:transitionName="imageTransition" 
      android:layout_width="match_parent" 
      android:layout_height="92.5dp" 
      android:src="@drawable/friday"/> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:src="@drawable/demo_calendar"/> 
     <com.zagum.work.virtualfitness.CustomTextView 
      xmlns:com.zagum.work.virtualfitness="http://schemas.android.com/apk/res/com.zagum.work.virtualfitness" 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:layout_marginTop="10dp" 
      com.zagum.work.virtualfitness:typeface="fonts/Roboto-Light.ttf"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      android:layout_marginBottom="40dp" 
      android:gravity="center" 
      android:paddingLeft="40dp" 
      android:paddingRight="40dp" 
      android:textSize="18sp" 
      android:textStyle="bold"/> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

Сделка:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       View image = mRootView.findViewById(R.id.share_image); 

       CurrentWorkoutFragment secondFragment = CurrentWorkoutFragment.newInstance(); 
       secondFragment.setSharedElementEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.transition_move)); 

       FragmentTransaction trans = getFragmentManager().beginTransaction(); 
       trans.replace(R.id.container, secondFragment); 
       trans.addToBackStack(null); 
       trans.addSharedElement(image, image.getTransitionName()); 
       trans.commit(); 
      } 

transition_move.xml

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"> 
    <changeImageTransform /> 
    <changeBounds/> 
</transitionSet> 

Но нет изображения анимации происходит. Он отображает в верхнем левом углу размеры.

+0

Это анимация интересно. Я бы сказал, если вы используете список фрагментов, когда вы нажимаете фрагмент, который он запускает, и анимация занимает весь экран. Все дополнительные представления уже находятся в фрагменте, но они скрыты, чтобы сменить какие-то флаги – VirtualProdigy

ответ

0

Отъезд this ответ.

Поскольку вид я делю между 2 фрагментами является потомком другого зрения (RelativeLayout) во 2-м фрагменте, необходимо добавить переход ChangeTransform к вашему TransitionSet.

В основном то, что вам нужно, это добавить <changeTransform/> в вашем transition_move.xml

 Смежные вопросы

  • Нет связанных вопросов^_^