1

I have developed an app already for Image Editing. Now I have add the feature of adding the text over the picture, same as Whatsapp status, Instagram etc.. I am going to add text using Edit Text, but than I want to move that text where ever I want all over the picture. How can we make EditText movable??

public void editIntent()
{
    RelativeLayout.LayoutParams params = new 
    RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
    RelativeLayout.LayoutParams.WRAP_CONTENT);

    EditText et = new EditText(this);
    et.setHint("Add a caption..");

    rl.addView(et);
}

rl is the object of relative layout

  • Do you try for this? Add some code here where you got stuck. – Chetan Joshi Jun 29 '17 at 05:37
  • No I haven't yet, but I am going to do like this(I have edited my question adding the code). Now I want to know that how can I make my edit text movable and save the picture along with that comment. – Ris Peterson Jun 29 '17 at 05:52

1 Answers1

0

Try with below solution :

android: move a view on touch move (ACTION_MOVE)

public class MyActivity extends Activity implements View.OnTouchListener {

TextView _view;
ViewGroup _root;
private int _xDelta;
private int _yDelta;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    _root = (ViewGroup)findViewById(R.id.root);

    _view = new TextView(this);
    _view.setText("TextView!!!!!!!!");

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 50);
    layoutParams.leftMargin = 50;
    layoutParams.topMargin = 50;
    layoutParams.bottomMargin = -250;
    layoutParams.rightMargin = -250;
    _view.setLayoutParams(layoutParams);

    _view.setOnTouchListener(this);
    _root.addView(_view);
}

public boolean onTouch(View view, MotionEvent event) {
    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
            _xDelta = X - lParams.leftMargin;
            _yDelta = Y - lParams.topMargin;
            break;
        case MotionEvent.ACTION_UP:
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            break;
        case MotionEvent.ACTION_POINTER_UP:
            break;
        case MotionEvent.ACTION_MOVE:
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
            layoutParams.leftMargin = X - _xDelta;
            layoutParams.topMargin = Y - _yDelta;
            layoutParams.rightMargin = -250;
            layoutParams.bottomMargin = -250;
            view.setLayoutParams(layoutParams);
            break;
    }
    _root.invalidate();
    return true;
}}
Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43