2

私は共有要素を使用してフラグメント間の遷移が必要なプロジェクトに取り組んでいます。ほぼすべてを試しましたが、トランジション効果は効きません。Android:共有要素のフラグメント化の変更

私はTimelineActivityというアクティビティを持っています。私は、2つのフラグメント、TimelineActivityに動的に追加されたListFragment、およびDetailFragmentを持っています。

ListFragment内のListView内のアイテムをクリックするたびに、そのフラグメントはDetailFragmentに置き換えられます。

<LinearLayout 
    android:id="@+id/transition" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFF" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:transitionName="selectClientTransition"> 
    </LinearLayout> 

と私fragment_detail.xmlに、私は次のようしている:私が持っているリストビューのレイアウトである私のlistview_row.xmlで

@Override 
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

    DetailFragment fragment = DetailFragment.newInstance(); 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     fragment.setSharedElementEnterTransition(new ChangeBounds().setDuration(2000)); 
     fragment.setEnterTransition(new ChangeBounds().setDuration(2000)); 
     setExitTransition(new ChangeBounds().setDuration(2000)); 
     fragment.setSharedElementReturnTransition(new ChangeBounds().setDuration(2000)); 
    } 

    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); 

    fragment.setAllowEnterTransitionOverlap(true); 
    fragment.setAllowReturnTransitionOverlap(true); 

    ft.replace(R.id.timeline_container, fragment); 
    ft.addSharedElement(view.findViewById(R.id.transition), "selectClientTransition"); 
    ft.addToBackStack(null); 

    // Start the animated transition. 
    ft.commit(); 
} 

<LinearLayout 
       android:id="@+id/transition" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#FFF" 
       android:orientation="vertical" 
       android:padding="10dp" 
       android:transitionName="selectClientTransition" 
       android:weightSum="12"> 
</LinearLayout> 

私はこれを追加しました私のAppThemeに

<item name="android:windowContentTransitions">true</item> 

破棄されたフラグメントは置き換えられますが、正常に機能していますが、変更の影響はありません。私は本当にここにこだわって何でも歓迎します。事前に

おかげで

答えて

0

私はちょうど私が私のListViewのために、通常の文字列配列に切り替えた場合、私は、それにもっとして1つの要素でarrayadapterカスタムを使用するときにのみ起こることが判明、すべてが同じ、正常に動作しますリストビューにカスタム配列アダプタを持つ要素が1つしかない場合、すべて正常に動作します。

0

リスト内の各要素に固有の遷移名を設定する必要があります。ここでは例です:

アダプタのgetViewメソッドメソッドセット遷移名:onItemClick方法で

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    // your code... 

    sharedView.setTransitionName(String.valueOf("transition_name_") + position); 
} 

DetailFragmentに遷移名を送信します。DetailFragmentのonCreateViewメソッドセット遷移名に

@Override 
public void onListItemClick(ListView l, View v, int position, long id) { 
    DetailFragment fragment = DetailFragment.newInstance(); 
    View sharedView = v.findViewById(R.id.shared_view); 

    Bundle arguments = new Bundle(); 
    arguments.putString(DetailFragment.TRANSITION_NAME, sharedView.getTransitionName()); 
    fragment.setArguments(arguments); 

    // the rest of your code (replacing fragments, etc)... 
} 

を表示するには:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    // your code... 

    View sharedView = inflatedLayout.findViewById(R.id.shared_view); 
    sharedView.setTransitionName(getArguments().getString(TRANSITION_NAME)) 
} 
関連する問題