2016-12-07 12 views
0

リサイクラービューがあります。 recyclerviewアイテムのonclickの中で、共有要素の移行を適用しました。ここ は、リサイクル・ビュー・アダプタです:共有要素の移行Androidが動作しない

@Override 
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.dashboard_location_item, parent, false); 
    //final TextView locationName = (TextView)view.findViewById(R.id.locationName); 
    //String transitionName = locationName.getTransitionName(); 
    // locationName.setTransitionName("testing"); 
    final ViewHolder vh = new ViewHolder(view); 

    view.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      int pos = vh.getAdapterPosition(); 
      if(pos != RecyclerView.NO_POSITION) { 

       final String cityName = mItems[pos]; 
       Log.d(TAG,"city name : " + cityName); 
       Intent intent = new Intent(mCtx, DashboardDetailPageActivity.class); 

       // Get the transition name from the string 
       TextView locationName = (TextView)view.findViewById(R.id.locationName); 
       String transitionName = locationName.getTransitionName(); 

       ActivityOptionsCompat options = 

         ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) mCtx, 
           locationName, // Starting view 
           transitionName // The String 
         ); 
       //Start the Intent 
       mCtx.startActivity(intent, options.toBundle()); 
       //transitionToActivity(DashboardDetailPageActivity.class, vh, cityName, view); 
      } 
     } 
    }); 



    return vh; 
} 

はここだcardviewのための私のレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 

<ImageView 
    android:id="@+id/locationIcon" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    /> 
<TextView 
    android:id="@+id/locationName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/location" 
    android:textColor="@color/white" 
    android:layout_gravity="center" 
    android:textSize="@dimen/textsize_18" 
    android:transitionName="@string/title" 
    android:textAllCaps="true" 
    android:gravity="center"/> 

ここで、私の最後の活動のレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/navigationDrwaerSerachLayout" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/dash_toolbar_height" 
      android:background="@drawable/city_image" 
      app:elevation="0dp"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/toolbar_height2" 
       android:minHeight="@dimen/toolbar_height2" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:layout_scrollFlags="scroll|enterAlways|snap" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:id="@+id/cityIcon" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:transitionName="testing" /> 

       <TextView 
        android:id="@+id/cityNameTextView" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:text="@string/location" 
        android:textAllCaps="true" 
        android:textColor="@color/white" 
        android:textSize="@dimen/textsize_18" 
        android:transitionName="@string/title" /> 
      </FrameLayout> 
     </android.support.design.widget.AppBarLayout> 


     <FrameLayout 
      android:id="@+id/sample2_content" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/navigationDrwaerSerachLayout"> 


     </FrameLayout> 

    </RelativeLayout> 

    <com.lapism.searchview.SearchView 
     android:id="@+id/searchView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="com.lapism.searchview.SearchBehavior" /> 


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

<include layout="@layout/nav" /> 

トランジション効果が動作していません。それは、開始アクティビティから最終アクティビティに移行します。ここで問題は何ですか?

+0

あなたの問題はまだ解決しましたか? –

答えて

0

リサイクラビューアダプタからアニメーションを作成するのではなく、親アクティビティからアニメーションを作成しました。コンテキストに問題があるはずです。

1

固有の遷移名が必要です。リスト項目からアニメートする場合は、ビューの遷移名を各リスト項目に固有のものに設定し(リスト項目のアダプタ位置またはIDの使用を検討する)、そのユニークな遷移名をターゲットアクティビティに渡すまたは断片である。ターゲットビューでは、idでビューを見つけて、渡したものにトランジション名を設定して、2つのビューをトランジション名でリンクします。

あなたのコードには他の問題があるかもしれませんが、直面したことに直ちに気がついたことがあります。

0

テーマでウィンドウコンテンツの切り替えを有効にしましたか?

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="android:windowContentTransitions">true</item> 
</style> 
関連する問題