私が直面している問題は次のとおりです。
- 相対レイアウトの中央に垂直方向の線形レイアウトで動的ボタンを作成しました。
- 次に、最初のボタンの右下に表示される線形レイアウトの上に画像を追加したいと思います。
しかし、2日間格闘した後も、まだ正しく理解できませんでした. 「画像」は最初のボタンの中央に表示されています。
アプリにしたいイメージ。
これは特定のコードです:
///outermost layout
RelativeLayout L1 = new RelativeLayout(this);
L1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
//For image overlapping on linear layout
FrameLayout FrameLayout = new FrameLayout(this);
RelativeLayout.LayoutParams RelativeParam = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
//Place all dynamic button inside here -vertical
LinearLayout L2 = new LinearLayout(this);
L2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
L2.setOrientation(LinearLayout.VERTICAL);
ImageView handpointer;
handpointer = new ImageView(this);
//grab the imageview and load the animations
handpointer.setImageDrawable(getResources().getDrawable(R.drawable.hand));
これは、すべての動的ボタンがレイアウト L2 に追加されるコードです。
L2.addView(b);
L2.addView(b);
}
RelativeLayout.LayoutParams Param = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Param.setMargins(0, 70, 0, 0);
L1.addView(FrameLayout,Param);
Param.addRule(RelativeLayout.CENTER_HORIZONTAL);
FrameLayout.addView(L2,Param);
RelativeParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
FrameLayout.addView(handpointer);
Drawable drawable = getResources().getDrawable(R.drawable.snail_menu);
L1.setBackgroundDrawable(drawable);
this.setContentView(L1);
助けてくれて本当にありがとう!