我有一个程序,我想在触摸事件的坐标处放置一个图像.我现在有坐标我需要帮助才能在那里放置图像.我将使用drawable.
编辑**我也想将它覆盖在另一个图像上.我找不到任何关于此的文件.我认为应该很容易.
谁能帮我?
编辑****知道了,现在我只需弄清楚如何在触摸点而不是左上角找到图像的中间位置:
final View touchView2 = findViewById(R.id.ImageView02);
touchView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.v("x,y",event.getY()+","+event.getX());
touchView2.bringToFront();
int y = (int)event.getY();
int x = (int)event.getX();
touchView2.layout(x, y, x+48, y+48);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
Drawable recycle_bin = context.getResources().getDrawable(android.R.drawable.ic_menu_delete);
int w = recycle_bin.getIntrinsicWidth();
int h = recycle_bin.getIntrinsicHeight();
int x = getWidth()/2 - w/2;
int y = getHeight() - h - 5;
recycle_bin.setBounds( x, y, x + w, y + h );
recycle_bin.draw( canvas );
Run Code Online (Sandbox Code Playgroud)
这就是我在底部中心绘制回收站图标的方法
| 归档时间: |
|
| 查看次数: |
12006 次 |
| 最近记录: |