将按钮移出屏幕

时间:2013-11-19 10:16:54

标签: java android

当按钮边距超过屏幕分辨率时,按钮会停止增长,是否有解决方法?

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button testButton = (Button) findViewById(R.id.testButton);
        final Handler handler = new Handler();

        Thread th = new Thread() {

            @Override
            public void run() {

                RelativeLayout.LayoutParams params = (LayoutParams) testButton
                        .getLayoutParams();
                params.topMargin += 10;
                params.leftMargin += 10;
                testButton.setLayoutParams(params);
                handler.postDelayed(this,100);
            }
        };

        handler.postDelayed(th,100);
    }

1 个答案:

答案 0 :(得分:0)

您应该使用翻译动画来执行此操作。尝试这样的事情:

Display display = getWindowManager().getDefaultDisplay(); 
int widthScreen = display.getWidth();

Animation animation = new TranslateAnimation(0, widthScreen ,0, widthScreen);
animation.setDuration(1000);
animation.setFillAfter(true);
testButton.startAnimation(animation);
testButton.setVisibility(0);

让我知道它是否有效。