如何创建边缘动态图像视图android

时间:2012-10-17 05:16:50

标签: android

请给我示例移动图像到我的保证金目的地

说明

image        x (margin move image)

如果使用拖动图像移动的图像停止移动到我的边距

imageView.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                int eid = event.getAction();
                switch (eid) {
                case MotionEvent.ACTION_MOVE:
                    RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
                    int x = (int) event.getRawX();
                    //int y = (int) event.getRawY();
                    TextView text = (TextView) findViewById(R.id.editText1);
                    text.setText("1");
                   mParams.setMargins(0, 0, 70, 0);
                    mParams.leftMargin = x+0;
                    //mParams.

                    imageView.setLayoutParams(mParams);

                    break;
                default:
                    break;
                }
                return true;
            }
        }

1 个答案:

答案 0 :(得分:1)

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
        Gravity.NO_GRAVITY);

我错过的第三个参数(Gravity.NO_GRAVITY)。使用它,您可以在设置宽度/高度的任何地方定位视图。

来自Android. How to move the imageview(set position/margin) when it is created

相关问题