0

removeView メソッドを呼び出すときにボタンのオフセットを無効にするにはどうすればよいですか? 削除ボタンを押したら

私が得る:

デフォルトの removeView メソッドの結果

私は欲しい:

私が必要なもの

私がすることができます?できれば、どうやって。そうでない場合は、代わりに何ができますか。


代わりに、同じ位置に新しいボタンを追加するため、ボタンを削除するだけです。

しかし、たとえば Button0 を削除するなど、removeView を使用してボタンを削除すると、ボタン Button1、Button2、Button3 が左に移動しました。Button0 を削除した後、ボタンをその位置に配置する必要があります

4

2 に答える 2

1

使用する

button1.setVisibility(View.INVISIBLE);
于 2012-06-30T10:55:22.807 に答える
0

次のように試してください:

private void removeView() {
linearLayout = (LinearLayout) findViewById(R.id.linearlayout);
int count = linearLayout.getChildCount();
if (count - 2 > 0) {
linearLayout.removeViewAt(count - 2);
}
}

編集:または、レイアウトのようにidでボタンを削除できます:

private void removeView() {
  LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear);
  Button btn_second= (Button) findViewById(R.id.second);
  linearLayout.removeView(btn_second);
}
于 2012-06-30T11:06:09.133 に答える