0

ViewHelper.setPivotY(test, 0);メソッドを設定しようとしましonClick()たが、うまくいきません。アニメーションは引き続き centerY にスケーリングされます。これが私のコードです。どこが間違っているのかわからない?

public class NewClassTest extends Activity{

LinearLayout test;
FrameLayout content;
Button btn;

boolean toggle = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_activity);

    test = (LinearLayout) findViewById(R.id.test);

    content = (FrameLayout) findViewById(R.id.content);
    content.setVisibility(View.INVISIBLE);

    btn = (Button) findViewById(R.id.button1);
    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // ViewHelper.setPivotY(test, 0); does not work
            runAnimation(toggle);
            toggle = !toggle;
        }
    });
    ViewHelper.setPivotY(test, 0); // work

}

private void runAnimation(boolean in){
    AnimatorSet animSet = new AnimatorSet();
    ObjectAnimator anim = null, anim2 = null;
            // ViewHelper.setPivotY(test, 0); also does not work
    if(in){
        anim = ObjectAnimator.ofFloat(test, "scaleY", 1, 1 - (((float)content.getHeight()) / ((float) test.getHeight())));
        anim2 = ObjectAnimator.ofFloat(content, "translationY", content.getHeight(), 0);
        animSet.addListener(new Animator.AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
                // TODO Auto-generated method stub

                content.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationCancel(Animator animation) {
                // TODO Auto-generated method stub

            }
        });
    }else {
        anim = ObjectAnimator.ofFloat(test, "scaleY", 1 - ((float)content.getHeight()) / ((float) test.getHeight()), 1);
        anim2 = ObjectAnimator.ofFloat(content, "translationY", 0, content.getHeight());
        animSet.addListener(new Animator.AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                // TODO Auto-generated method stub
                content.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                // TODO Auto-generated method stub

            }
        });
    }
    animSet.setDuration(1000).play(anim2).with(anim);
    animSet.start();
}

お手伝いありがとうございます!。

4

1 に答える 1