このコードをデモとして試してください:
//Main Rel_Layout
RelativeLayout scrollHolder = new RelativeLayout(this);
scrollHolder.setId(++myid);
RelativeLayout.LayoutParams scrollHolderParams = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
scrollHolder.setLayoutParams(scrollHolderParams);
scrollHolder.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
// Image Holder Layout
RelativeLayout imgHolder = new RelativeLayout(this);
imgHolder.setId(++myid);
RelativeLayout.LayoutParams imgHolderParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imgHolder.setLayoutParams(imgHolderParams);
imgHolder.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
//imgHolder.setBackgroundColor(Color.BLUE);
imgHolder.setLayoutParams(imgHolderParams);
// Image Object
ImageView image2 = new ImageView(this);
image2.setId(++myid);
image2.setBackgroundColor(Color.BLUE);
//int resId = HomePage.this.getResources().getIdentifier("img2", "drawable", HomePage.this.getPackageName());
image2.setImageResource(R.drawable.img2);
// set image to its holder
imgHolder.addView(image2);
// set imgHolder to main Layout
scrollHolder.addView(imgHolder);
// set main layout as content-view
setContentView(scrollHolder);
// this will sure help you.
古い最も簡単な方法は次のとおりです。 [1] EditText をRelative
-layoutに追加します。
layout-center-horizontal = true および layout-center-vertical = true
[2] xml で Visibility=GONE を設定します
[3] コード ファイルでそのオブジェクトを取得し、その「テキスト値」とVisibility = VIEW.Visibleを設定します。