Monday, April 13, 2015

Android : Android Buttons in Code same size



I want to add buttons dynamically and to have them same sizes. Buttons count depends on length of a word. It looks quite allright when I have long word:


http://i.stack.imgur.com/zZ3FS.jpg


But when I have only 1 letter as a word it looks like this:


http://i.stack.imgur.com/IyYhd.jpg


This is my code:



public void loadButtons() {
buttonsLayout = (LinearLayout) findViewById(R.id.buttons_Layout);
answerButtons = new Button[word.length()];


for (int i = 0; i < word.length(); i++) {
answerButtons[i] = new Button(this);
answerButtons[i].setText(null);
LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,1f);
answerButtons[i].setLayoutParams(Params1);


answerButtons[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
buttonsLayout.addView(answerButtons[i]);
}


How could I achieve that? :) Thanks


No comments:

Post a Comment