在GestureOverlayView中添加一个孩子,我触摸了android?

Dro*_*Dev 10 android view gesture

如何在一个手势覆盖视图中添加一个孩子(一个布局),在我触摸该视图的位置.....是否可以根据位置的坐标来定位它?

vAr*_*rDo 1

对于 API 11 (Android 3.0.x) 及更高版本:您可以使用View.setX()View.setY()。有关详细信息,请参阅API 文档。

对于所有 API 版本:您可以使用RelativeLayoutRelativeLayout.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);
Run Code Online (Sandbox Code Playgroud)