0

У меня есть фрагмент, содержащий RecyclerView (сам фрагмент находится внутри ViewPager). RecyclerView содержит ImageView, а другой фрагмент также содержит ImageView, я хочу сделать переход с использованием sharedElement этих ImageView.I пробовал все, но не работал, даже я создал реплику, как показано здесь here, но ничего не работает. Мой код:Переход общего элемента на RecyclerView

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_album, container, false); 
    return view; 
} 

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    albumlistClick = (AlbumlistClick) getActivity(); 
    albumRecycle = (RecyclerView) view.findViewById(R.id.albumRecycle); 
    albumRecyclerAdapter = new AlbumRecyclerAdapter(getContext()); 
    layoutManager = new GridLayoutManager(getContext(), 2); 
    albumRecycle.setLayoutManager(layoutManager); 
    albumRecycle.setAdapter(albumRecyclerAdapter);} 

RecyclerView адаптер и ViewHolder

private class AlbumRecyclerAdapter extends RecyclerView.Adapter<AlbumViewHolder> { 

    Context context; 
    LayoutInflater inflater; 
    ArrayList<SongDB> albumList = MainActivity.AlbumList; 

    public AlbumRecyclerAdapter(Context context) { 
     this.context = context; 
    } 

    @Override 
    public AlbumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     inflater = LayoutInflater.from(parent.getContext()); 
     View view = inflater.inflate(R.layout.custom_album_list, parent, false); 
     AlbumViewHolder albumViewHolder = new AlbumViewHolder(view); 
     return albumViewHolder; 
    } 

    @Override 
    public void onBindViewHolder(final AlbumViewHolder holder,final int position) { 
     SongDB curr = albumList.get(position); 
     holder.album_name.setText(curr.getAlbum()); 
     holder.album_artist.setText(curr.getArtist()); 
     Glide.with(context) 
       .load("file://" + curr.getAlbumDB().getAlbumArt()) 
       //.load(R.drawable.image) 
       .error(R.drawable.play_icon) 
       .centerCrop() 
       .crossFade() 
       .into(holder.album_image); 

      ViewCompat.setTransitionName(holder.album_image,String.valueOf(position) + "_albumart"); 


    } 

    @Override 
    public int getItemCount() { 
     return albumList.size(); 
    } 


} 

private class AlbumViewHolder extends RecyclerView.ViewHolder { 
    ImageView album_image; 
    TextView album_name, album_artist; 

     public AlbumViewHolder(final View itemView) { 
     super(itemView); 

     album_image = (ImageView) itemView.findViewById(R.id.artist_image); 
     album_name = (TextView) itemView.findViewById(R.id.album_name); 
     album_artist = (TextView) itemView.findViewById(R.id.album_artist); 
     itemView.setOnClickListener(
       new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 

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


          int data = albumRecycle.getChildAdapterPosition(itemView); 
          Trail album_list = new Trail(data); 

          Transition transition = TransitionInflater.from(getContext()).inflateTransition(R.transition.transition); 

          album_list.setSharedElementEnterTransition(transition); 
          album_list.setSharedElementReturnTransition(transition); 

          //album_image = (ImageView) itemView.findViewById(R.id.artist_image); 

          getActivity().getSupportFragmentManager() 
            .beginTransaction() 
            .replace(R.id.albumlistContainer, album_list) 
            .addToBackStack(null) 
            .addSharedElement(album_image, "albumart") 
            .commit(); 
         } 

        } 
       } 
     ); 
    } 
} 

Компоновка Код для другой деятельности

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/white" 
android:clickable="true" 
tools:context="com.example.vitymspaul.asdfg.Trail"> 

<!-- TODO: Update blank fragment layout --> 

<ImageView 
    android:layout_width="250dp" 
    android:layout_height="250dp" 
    android:id="@+id/artist_image" 
    android:layout_gravity="center" 
    android:scaleType="centerCrop" 
    android:transitionName="albumart" 
    android:clickable="true" 
    tools:ignore="ContentDescription,UnusedAttribute"/> 

Код для расположения customview в recyclerview

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="180dp" 
android:layout_height="230dp" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_margin="5dp" 
app:cardCornerRadius="5dp" 
app:cardElevation="6dp"> 
<ImageView 
    android:id="@+id/artist_image" 
    android:layout_width="180dp" 
    android:layout_height="180dp" 
    android:layout_above="@+id/imagebelow" 
    android:layout_gravity="center_horizontal|top" 
    android:scaleType="centerCrop" 
    tools:ignore="ContentDescription" 
    /> 

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



    <RelativeLayout 
     android:id="@+id/imagebelow" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="center_horizontal|bottom" 
     android:background="#ffe3e3"> 

     <TextView 
      android:id="@+id/album_name" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="20dp" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#0a0000" 
      android:textSize="20dp" /> 

     <TextView 
      android:id="@+id/album_artist" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/album_name" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="5dp" 
      android:singleLine="true" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#828282" /> 
    </RelativeLayout> 

</RelativeLayout> 

Transition файл

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

Вы установили android: transitionName ?? – sJy

+0

да я добавил имя перехода –

+0

опубликовать ваш код макета – sJy

ответ

0

Попробуйте Раздувание переход двигаться по умолчанию android.R.transition.move.

Transition transition = TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move); 
album_list.setSharedElementEnterTransition(transition); 
album_list.setSharedElementReturnTransition(transition); 
+0

все еще переход нет там, где его видно. –

+0

На какой версии Android вы тестируете ??? – sJy

+0

Я пытаюсь на api 22 –

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