ボタンの行を動的に作成しましたが、ボタンの 1 つにもう少しテキストがあります。その行のボタンは、より多くのテキストを含むボタンと同じサイズですが、これらのボタンの行は、他の行の他のボタンよりも大きくなっています。以下は私のコードです:
LinearLayout dynamicview = (LinearLayout)findViewById(R.id.buttons);
for (int i = 0; i < 3; i++) {
LinearLayout row = new LinearLayout(this);
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
for (int j = 0; j < 5; j++) {
Button btnTag = new Button(this);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT,1.0f);
btnTag.setLayoutParams(param);
Display display=getWindowManager().getDefaultDisplay();
int width=display.getWidth();
btnTag.setText("" + (j + 1 + (i * 5)));
btnTag.setId(j + 1 + (i * 5));
btnTag.setWidth(width/5);
if(btnTag.getId() == 13) {
btnTag.setText("has more txt");
}
if(btnTag.getId() == 14) {
btnTag.setVisibility(View.INVISIBLE);
}
if(btnTag.getId() == 15) {
btnTag.setText("C");
}
row.addView(btnTag);
}
dynamicview.addView(row);
}
XML の R.id.buttons は次のとおりです。
<LinearLayout
android:id="@+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
</LinearLayout>
3列のボタンをすべて同じ幅と高さにする方法があれば教えてください。
ありがとうございました。