アニメーション実装テスト

This commit is contained in:
ろむねこ 2023-12-18 12:30:27 +09:00
parent 051a6e582f
commit 7df53d9f40
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 19 additions and 9 deletions

View File

@ -32,6 +32,15 @@ public class MainActivity extends AppCompatActivity {
NavHostFragment navHostFragment = (NavHostFragment) supportFragmentManager.findFragmentById(R.id.nav_host_fragment); NavHostFragment navHostFragment = (NavHostFragment) supportFragmentManager.findFragmentById(R.id.nav_host_fragment);
// Animation // Animation
if (navHostFragment != null) {
MaterialSharedAxis exitTransition = new MaterialSharedAxis(MaterialSharedAxis.Z, true);
exitTransition.setDuration(500);
navHostFragment.setExitTransition(exitTransition);
MaterialSharedAxis reenterTransition = new MaterialSharedAxis(MaterialSharedAxis.Z, false);
reenterTransition.setDuration(500);
navHostFragment.setReenterTransition(reenterTransition);
}
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav); BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav);

View File

@ -11,6 +11,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.google.android.material.transition.MaterialSharedAxis;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
* Use the {@link HomeTopFragment#newInstance} factory method to * Use the {@link HomeTopFragment#newInstance} factory method to
@ -52,15 +54,14 @@ public class HomeTopFragment extends Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Transition
TransitionInflater inflater = TransitionInflater.from(requireContext()); MaterialSharedAxis enterTransition = new MaterialSharedAxis(MaterialSharedAxis.Z, true);
setEnterTransition(inflater.inflateTransition(android.R.transition.slide_top)); enterTransition.setDuration(500);
setExitTransition(inflater.inflateTransition(android.R.transition.slide_bottom)); setEnterTransition(enterTransition);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1); MaterialSharedAxis returnTransition = new MaterialSharedAxis(MaterialSharedAxis.Z, false);
mParam2 = getArguments().getString(ARG_PARAM2); returnTransition.setDuration(500);
} else { setReturnTransition(returnTransition);
}
} }
@Override @Override