マテリアル デザインのビデオでは、ビューが非常にスムーズに伸縮します。昔は古い Android API を使ってそれを達成しようとしましたが、それは本当にコストがかかり、遅かったです。
これらの効果を達成するための Android-L の新しい API はありますか?
マテリアル デザインのビデオでは、ビューが非常にスムーズに伸縮します。昔は古い Android API を使ってそれを達成しようとしましたが、それは本当にコストがかかり、遅かったです。
これらの効果を達成するための Android-L の新しい API はありますか?
android-L の新しいアニメーション API を使用して、このビデオで見られるほとんどの効果を簡単に作成できます。
表示効果
クリッピング サークルをアニメーション化して、ビューを表示または非表示にすることができます。これは、ビデオで [再生] ボタンをクリックしたときに表示されるものです。ボタンが展開され、メディア プレーヤーが表示されます。
非表示のビューを表示するコード ( source )
// previously invisible view
View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = myView.getWidth();
// create and start the animator for this view
// (the start radius is zero)
ValueAnimator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
anim.start();
上記のリンクをたどると、ビューを非表示にするコードを見つけることができます。
アクティビティの開始遷移と終了遷移
ビューがどのようにシーンに出入りするかを指定できます。
現在サポートされているトランジションは、爆発、スライド、およびフェードです。を拡張する遷移android.transition.Visibility
もサポートされています。
ビデオ全体で多くの例を見ることができます。
爆発終了トランジションのコード ( source )
// inside your activity
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
// set an exit transition
getWindow().setExitTransition(new Explode());
アクティビティ共有要素遷移
2 つのアクティビティ間で共有される要素が、それらの間でどのように遷移できるかを指定できます。
サポートされているトランジションは次のとおりです。
共有要素の移行を行うには、次のことを行う必要があります: ( source )
メソッドを使用しActivityOptions.makeSceneTransitionAnimation
ます。
// get the element that receives the click event
final View imgContainerView = findViewById(R.id.img_container);
// get the common element for the transition in this activity
final View androidRobotView = findViewById(R.id.image_small);
// define a click listener
imgContainerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(this, Activity2.class);
// create the transition animation - the images in the layouts
// of both activities are defined with android:viewName="robot"
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(this, androidRobotView, "robot");
// start the new activity
startActivity(intent, options.toBundle());
}
});
私がまだ理解していないアニメーションの 1 つは、カレンダー アプリで見ることができる同じアクティビティ内の展開/縮小アニメーションです。
それについて私が言える唯一のことは、影を見ることができるので、彼らは仰角を使用していることです. ちょっとハックして再現できるか試してみます。