Emerrias
Emerrias

Reputation: 15

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

        }
    });
}

Upvotes: 0

Views: 392

Answers (2)

griffinjm
griffinjm

Reputation: 503

Because you're not assigning mParams to your buttons params.

mParams = upbutton.getLayoutParams();

Upvotes: 1

AdamM
AdamM

Reputation: 162

You seem to be increasing parameters for your RelativeLayout then assigning those to your button. So the button gets confused. Try looking for a set margin option or something on the actual button view.

Upvotes: 0

Related Questions