2

私が直面している問題は次のとおりです。

  1. 相対レイアウトの中央に垂直方向の線形レイアウトで動的ボタンを作成しました。
  2. 次に、最初のボタンの右下に表示される線形レイアウトの上に画像を追加したいと思います。

しかし、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);

助けてくれて本当にありがとう!

4

2 に答える 2

0

実行時に表示したい場所に、XML でボタンを配置します。そして、setVisibilityメソッドを使用して表示または非表示にします。それは実行可能な解決策ではありませんか?

于 2012-05-15T08:38:37.567 に答える