I'm creating a LinearLayout programmatically and I'm adding to this layout three buttons, but they're showed one on top of the other.
How I can show the buttons in line?
Reading around I probably understood that I need to set up a LayoutParams but I didn't figured out how..
I've tried with this but it didn't did the trick..
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); ll.addView(b1, layoutParams); ll.addView(b2, layoutParams); ll.addView(b3, layoutParams);
Gracias por cualquier ayuda!
Probably I needed to add more details.
I have also other stuff in the Layout but I does'n matter, I've created an additional layout just for the buttons.
Now the buttons are in line but they have different width.. : /
I've tried with this but it didn't help..
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f );
preguntado el 30 de junio de 12 a las 13:06
Lets you set buttons in horizontal line allignment.
But to give balanced space to all three buttons. you must set
weight property for all the three
Button objetos a
Do this for all buttons.
LinearLayout.LayoutParams params = button.getLayoutParams(); params.weight = 1; button.setLayoutParams(params);
to set weight for all buttons.
Regards, Aqif Hamid
All have MATCH_PARENT should have LayoutParams.WRAP_CONTENT in width or height (in at least one as per LinearLayout orientation )
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
LinearLayout gvDivisao = (LinearLayout) findViewById(R.id.gvDivisao); LayoutInflater inflater = getLayoutInflater(); LayoutParams btDivLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f); Button btDivA = (Button)inflater.inflate(R.layout.button_divisao, null); btDivA.setText("A"); gvDivisao.addView( btDivA, btDivLayoutParams);