TextView
をImageButton
の中心に設定する必要がありますが、コードを使用する必要があります。私はテキストをオンにすることができますが、私はそれを中心にすることはできません。ImageButtonの中央TextViewをプログラムで
コード:
RelativeLayout rLayout = new RelativeLayout(this);
TextView textView = new TextView(this);
textView.setText("text");
textView.setTextSize(25);
textView.setGravity(Gravity.CENTER);
final ImageButton iButton = new ImageButton(this);
iButton.setImageResource(R.drawable.button);
iButton.setBackgroundColor(Color.TRANSPARENT);
rLayout.addView(iButton);
rLayout.addView(textView);
linear.addView(rLayout);
このコードはIMAGEBUTTON上のテキストを設定しますが、左上に設定します。
は、なぜあなたは代わりのImageButtonとのTextViewのテキストと背景画像とボタンを使用していないしてみてください? – Thracian