1

クロスフェードを実行しようとしていますが、Android Developers のチュートリアルでは、アニメーションの長さとして「animationDuration」を使用しています。この「animationDuration」は、フェード アニメーションの持続時間がプロセッサの速度に応じて取得されるようになっていますか? 私はAndroidプログラミングに慣れていないので、このような単純なことはまだ慣れていません。

コードは次のとおりです。

public class CrossfadeActivity extends Activity {

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);
            }
        });

}

4

1 に答える 1

0

android.R.integer.config_shortAnimTime 定数を使用します。

int time = getResources().getInteger(android.R.integer.config_shortAnimTime);  

config_longAnimTimeconfig_mediumAnimTime定数も利用できます。

于 2016-05-23T14:24:03.107 に答える