1
我想做一個交叉淡入淡出,Android開發者教程使用「animationDuration」 作爲動畫的持續時間。是否應該檢索「animationDuration」,以便根據處理器的速度確定淡入淡出動畫的持續時間?我對android編程很陌生,所以這樣簡單的事情對我來說還是很陌生。什麼是檢索並緩存系統的默認「短」動畫時間?
下面的代碼:
公共類CrossfadeActivity延伸活動{
private View mContentView;
private View mLoadingView;
private int AnimationDuration;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crossfade);
mContentView = findViewById(R.id.content);
mLoadingView = findViewById(R.id.loading_spinner);
// Initially hide the content view.
mContentView.setVisibility(View.GONE);
// Retrieve and cache the system's default "short" animation time.
AnimationDuration = getResources().getInteger(
android.R.integer.config_shortAnimTime);
}
這裏的動畫類:
私人無效交叉淡入淡出(){
// Set the content view to 0% opacity but visible, so that it is visible
// (but fully transparent) during the animation.
mContentView.setAlpha(0f);
mContentView.setVisibility(View.VISIBLE);
// Animate the content view to 100% opacity, and clear any animation
// listener set on the view.
mContentView.animate()
.alpha(1f)
.setDuration(AnimationDuration)
.setListener(null);
// Animate the loading view to 0% opacity. After the animation ends,
// set its visibility to GONE as an optimization step (it won't
// participate in layout passes, etc.)
mLoadingView.animate()
.alpha(0f)
.setDuration(mShortAnimationDuration) //???
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mLoadingView.setVisibility(View.GONE);
}
});
}