简体   繁体   English

Android按钮不移动onclick

[英]Android Button Not moving onclick

I have an up button which I want to move up onClick but when I click on it it moves way to far and gets to the end of the screen and then shrinks down untill you cant see it. 我有一个向上按钮,我想将onClick向上移动,但是当我单击它时,它会移动到很远,到达屏幕末端,然后缩小直到您看不到它。 It moves up too much, but why? 它上升太多了,但是为什么呢? I only increase it by one unit? 我只增加一个单位?

final Button upbutton = (Button)findViewById(R.id.upbutton);

    upbutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams)

            upbutton.getLayoutParams();

            mParams.bottomMargin += 1;
            upbutton.setLayoutParams(mParams);

        }
    });
}

因为您没有将mParam分配给按钮参数。

mParams = upbutton.getLayoutParams();

You seem to be increasing parameters for your RelativeLayout then assigning those to your button . 您似乎在为RelativeLayout增加参数,然后将其分配给button So the button gets confused. 因此button变得混乱。 Try looking for a set margin option or something on the actual button view. 尝试在实际button视图上查找设置的边距选项或其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM