レイアウトにボタンを追加して、スペースが正しく機能するようにするためのプログラムがあります。このメソッドでは、テキストを変更するためにsetTextメソッドを使用しています。ただし、そのテキストは表示されません。 Here's what's being createdプログラムで追加されたボタンにテキストが表示されない
ここで私が使用しているコードです:あなたのコードは大丈夫です
public void addButtons() {
Button update = new Button(this);
RelativeLayout.LayoutParams updateParams = new RelativeLayout.LayoutParams(size.x/5, 200);
updateParams.addRule(RelativeLayout.CENTER_VERTICAL);
update.setLayoutParams(updateParams);
update.setPadding(padding, 0, 0, 0);
update.setText("Update Me!");
update.setTextColor(Color.BLUE);
update.setOnClickListener(new ClickHandler("install_install", this));
updateId = update.generateViewId();
update.setId(updateId);
layout.addView(update);
Button install = new Button(this);
RelativeLayout.LayoutParams installParams = new RelativeLayout.LayoutParams(size.x/5, 200);
installParams.addRule(RelativeLayout.RIGHT_OF, update.getId());
installParams.addRule(RelativeLayout.CENTER_VERTICAL);
install.setLayoutParams(installParams);
install.setPadding(padding, 0, 0, 0);
install.setText("Install LastBox");
install.setTextColor(Color.BLUE);
install.setOnClickListener(new ClickHandler("lastbox_install", this));
installId = install.generateViewId();
install.setId(installId);
layout.addView(install);
Button dlFamily = new Button(this);
RelativeLayout.LayoutParams dlFamilyParams = new RelativeLayout.LayoutParams(size.x/5, 200);
dlFamilyParams.addRule(RelativeLayout.RIGHT_OF, install.getId());
dlFamilyParams.addRule(RelativeLayout.ABOVE, install.getId());
dlFamily.setLayoutParams(dlFamilyParams);
dlFamily.setPadding(padding, 0, 0, padding);
dlFamily.setText("Download Family Build");
dlFamily.setTextColor(Color.BLUE);
dlFamily.setOnClickListener(new ClickHandler("family_build", this));
dlFamilyId = dlFamily.generateViewId();
dlFamily.setId(dlFamilyId);
layout.addView(dlFamily);
Button upFamily = new Button(this);
RelativeLayout.LayoutParams upFamilyParams = new RelativeLayout.LayoutParams(size.x/5, 200);
upFamilyParams.addRule(RelativeLayout.RIGHT_OF, install.getId());
upFamilyParams.addRule(RelativeLayout.BELOW, install.getId());
upFamily.setLayoutParams(upFamilyParams);
upFamily.setPadding(padding, padding, 0, 0);
upFamily.setText("Update Family Build");
upFamily.setTextColor(Color.BLUE);
upFamily.setOnClickListener(new ClickHandler("family_update", this));
upFamilyId = upFamily.generateViewId();
upFamily.setId(upFamilyId);
layout.addView(upFamily);
Button dlAdult = new Button(this);
RelativeLayout.LayoutParams dlAdultParams = new RelativeLayout.LayoutParams(size.x/5, 200);
dlAdultParams.addRule(RelativeLayout.RIGHT_OF, dlFamily.getId());
dlAdultParams.addRule(RelativeLayout.ABOVE, install.getId());
dlAdult.setLayoutParams(dlAdultParams);
dlAdult.setPadding(padding, 0, 0, padding);
dlAdult.setText("Download Adult Build");
dlAdult.setTextColor(Color.BLUE);
dlAdult.setOnClickListener(new ClickHandler("adult_build", this));
dlAdultId = dlAdult.generateViewId();
dlAdult.setId(dlAdultId);
layout.addView(dlAdult);
Button upAdult = new Button(this);
RelativeLayout.LayoutParams upAdultParams = new RelativeLayout.LayoutParams(size.x/5, 200);
upAdultParams.addRule(RelativeLayout.RIGHT_OF, upFamily.getId());
upAdultParams.addRule(RelativeLayout.BELOW, install.getId());
upAdult.setLayoutParams(upAdultParams);
upAdult.setPadding(padding, padding, 0, 0);
upAdult.setText("Update Adult Build");
upAdult.setTextColor(Color.BLUE);
upAdult.setOnClickListener(new ClickHandler("adult_update", this));
upAdultId = upAdult.generateViewId();
upAdult.setId(upAdultId);
layout.addView(upAdult);
}
適用したパディングを確認してください。パディングのためにテキストがボタン表示の外側に表示されることがあります。 –