Search code examples
androidbuttongravity

setGravity both BOTTOM and CENTER programmatically


I'm having problems placing a button inside a space of a GridLayout.

final Button prevButton = new Button(getApplicationContext());
GridLayout.LayoutParams param = new GridLayout.LayoutParams();
param.setGravity(Gravity.BOTTOM); // <-----------------------
prevButton.setTextColor(Color.parseColor("#FFFFFF"));
prevButton.setBackgroundDrawable(menuButton);
prevButton.setLayoutParams(param);
prevButton.setWidth(menuButtonWidth);
prevButton.setText("<");

I want the button to be at the very bottom of the screen, but I also want it to be in the center of it's space (like param.setGravity(Gravity.CENTER)). Is there a way to combine Gravity.BOTTOM and Gravity.CENTER programmatically (No XML)? Thank you!


Solution

  • You can use this .

    param.setGravity(Gravity.BOTTOM | Gravity.CENTER);