そのビューで触れたポイントでジェスチャーオーバーレイビューに子(レイアウト)を追加するにはどうすればよいですか.....場所の座標に従って配置することは可能ですか??
2 に答える
1
API 11 (Android 3.0.x) 以降の場合:View.setX()
とを使用できますView.setY()
。詳細については、 API ドキュメントを参照してください。
すべての API バージョン:RelativeLayout
およびを使用できますRelativeLayout.Layout
。具体的には、 から継承されたフィールドに余白ViewGroup.MarginLayoutParams
を設定します。私はそれが次のようになると思います:
RelativeLayout parentLayout = (RelativeLayout) findViewById(R.id.relative_layout);
LinearLayout newLayout = new LinearLayout(this); // or some other layout
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
// You can enter layout absolute dimensions here instead of 'wrap_content'.
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// Set your X and Y position here for new layout.
layoutParams.setMargins(100 /*left*/, 200 /*top*/, 0 /*right*/, 0 /*bottom*/);
parentLayout.addView(newLayout , layoutParams);
于 2012-07-06T18:40:24.337 に答える