Hello, how can I align the align buttons on the right side, one under the other of the code, in the class ButtonsLayout?

public class Activity extends Activity { private GLSurfaceView glView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); glView = new GLSurfaceView(this); // glView здесь куча параметров для glView которые по идее не имеют отношения к вопросу this.setContentView(glView); this.addContentView(new ButtonsLayout(this), new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); } } 

Here is the ButtonsLayout class.

 public class ButtonsLayout extends LinearLayout { public ButtonsLayout(Context context) { super(context); LinearLayout.LayoutParams rightGravityParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); rightGravityParams.gravity = Gravity.RIGHT; Button btn1 = new Button(context); btn1.setText("Button1"); addView(btn1, rightGravityParams); Button btn2 = new Button(context); btn2.setText("Button2"); addView(btn2, rightGravityParams); } } 

I need the buttons to be on the right and one below the other. And I get that they are on the left and on one line.

  • one
    Why do you want to do this programmatically, and not through xml layout? - Barmaley
  • It is also possible through XML, but through XML I could not add using the addContentView () method, but it turned out programmatically. If there is a solution where the class loads the XML layout and then is inserted using addContentView (), then this would be even better. - fantastic
  • LayoutInflater inflater = getLayoutInflater(); View tmpView; tmpView = inflater.inflate(R.layout.extra_layout, null); getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); - Barmaley
  • I created test.xml in the layout folder. But after trying to get it: View tmpView = inflater.inflate (R.layout.test, null); Error flies: android.content.res.Resources $ NotFoundException: Resource ID # 0x7f040027 - fantastic
  • one
    Where does R.layout.test look? Such a feeling axis does not see test.xml - Barmaley

0