LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 210,Gravity.CENTER_VERTICAL); visualizerLayout.setLayoutParams(params); visualizerLayout.addView(eq); 

It is drawn to the very bottom of the page, but it turns out under the elements below which the layout is drawn.

210 is the value that I have to look at if I understand correctly (calculated from the size of the elements enclosed in the view).

Gravity.CENTER_VERTICAL if I understand correctly, should just adjust the elements inside the layout so that they tend to occupy a central position.

How to make eq view drawn in the middle of the page?

  • one
    and what for 210? And the third parameter in the constructor is weight, what did you mean by writing Gravity.CENTER_VERTICAL there? - rasmisha
  • And what is the question then? I just reread 5 times and did not quite understand, under what elements does it appear? - rasmisha
  • tell me more: - where is visualizerLayout; - what exactly is needed: position the visualizerLayout in the center of the screen or eq in the center of the visualizerLayout. - afiki
  • We want an example of how it is, of how you need it! - andreich

1 answer 1

LinearLayout throws widgets onto the stack (horizontal or vertical). for centering it is easier to use RelativeLayout. and centering is set by rule

 params.addRule(RelativeLayout.CENTER_IN_PARENT); // или CENTER_VERTICAL. 

and LayoutParams in this case should be used not for the layout itself, but for View eq.