I'm relatively new to android and I'm trying to create a linear layout with 2 buttons and text view. The buttons will allow me to increase and decrease the value of the text view in the middle of them.
Basically I want to achieve something like this:
I have already created a function for the creation of textviews and it works fine. Now I want to create 2 buttons which I managed to do on my own but I seem to fail when it comes to making them align with eachother as shown in the image above.
The code I wrote to create textviews dynamically is given below:
void create_text(int i, int amountid, int H, int W)
{
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.imgLayout2);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(340, 340);
parms.gravity = Gravity.CENTER;
parms.setMargins(20, 0, 20, 0);
final TextView textView = new TextView(this);
textView.setLayoutParams(parms);
textView.setText(" x "+i);
textView.setTypeface(null, Typeface.BOLD);
linearLayout.addView(textView);
textView.setId(amountid);
textView.getLayoutParams().height = H;
textView.getLayoutParams().width = W;
}
I want to create buttons in the same function that will be before and after the text view and perfectly aligned with it (my actual problem and something that I have failed to do so far). Any help is very much appreciated.