使用android中的搜索栏控制帧动画速度

时间:2015-04-13 14:16:55

标签: android eclipse

我有以下代码在搜索栏的帮助下改变帧动画的不透明度,现在我试图在这个搜索栏的帮助下控制帧动画的持续时间,任何人都可以帮我告诉那个如果有可能吗?

代码:

ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);

        //Create a new AnimationDrawable
        final AnimationDrawable myAnimationDrawable 
            = createAnimationDrawable();

        //apply the new AnimationDrawable
        myAnimation.setImageDrawable(myAnimationDrawable);

        SeekBar setAnimationAlpha = (SeekBar)findViewById(R.id.setalpha);
        Button startAnimation = (Button)findViewById(R.id.startanimation);
        Button stopAnimation = (Button)findViewById(R.id.stopanimation);

        startAnimation.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if(!myAnimationDrawable.isRunning()){
                    myAnimationDrawable.start();
                }
            }});

        stopAnimation.setOnClickListener(new Button.OnClickListener(){

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if(myAnimationDrawable.isRunning()){
                    myAnimationDrawable.stop();
                }
            }});

        setAnimationAlpha.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                myAnimationDrawable.setAlpha(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }});

    }

    private AnimationDrawable createAnimationDrawable(){

        AnimationDrawable newAnim = new AnimationDrawable();

        newAnim.addFrame(getResources().getDrawable(R.drawable.android_1), 90);
        newAnim.addFrame(getResources().getDrawable(R.drawable.android_2), 90);
        newAnim.addFrame(getResources().getDrawable(R.drawable.android_3), 90);
        newAnim.addFrame(getResources().getDrawable(R.drawable.android_4), 90);
        newAnim.addFrame(getResources().getDrawable(R.drawable.android_5), 90);
        newAnim.addFrame(getResources().getDrawable(R.drawable.android_6), 90);
        newAnim.addFrame(getResources().getDrawable(R.drawable.android_7), 90);
        newAnim.setOneShot(false);

        return newAnim;
    }

}

0 个答案:

没有答案