1

In My Custom AbsoluteLayout, I override updateViewLayout as follows:

The parameter "view" here is an EditText.

  @Override public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
    super.updateViewLayout(view, params);
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    view.setLayoutParams(params);
  }

This causes the EditText to not wrap when it reaches the end of the custom layout. Here's a screenshot to show what's happening enter image description here

EDIT : Just to clarify, it happens after dragging the EditText to anywhere on the view. Otherwise it works smoothly before dragging. In case it's cause is inside the onDrop Method. This is my OnDrop Method in my custom layout. I implemented by following this guide

public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
      DragView dragView, Object dragInfo)
  {
    final EditText v = (EditText) dragInfo;

    int dragViewWdith = dragView.getWidth();
    int dragViewHeight = dragView.getHeight();
    int layoutWidth = this.getWidth();
    int layoutHeight = this.getHeight();
    int left = x - xOffset;
    int top = y - yOffset;

    L.e("layoutWidth : " + layoutWidth);

    if (left < 0) {
      left = 0;
    }
    if (left + dragViewWdith > layoutWidth) {
      left = layoutWidth - dragViewWdith;
    }
    if (top < 0) {
      top = 0;
    }
    if (top + dragViewHeight > layoutHeight) {
      top = layoutHeight - dragViewHeight;
    }

    final MyAbsoluteLayout.LayoutParams params = new MyAbsoluteLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT, left, top);
    v.post(new Runnable() {
      @Override public void run() {
        updateViewLayout(v, params);
      }
    });
Vincent Paing
  • 2,308
  • 3
  • 17
  • 29

1 Answers1

0

Try to do it inside the onCreate method of your activity.

You will need to know the type of Parent ViewGroup that the editText belongs to first, so if its a RelativeLayout, you would do this.

  1. Get a handler on the ediText first.
  2. Set your layoutParams as per below:

    RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

  3. You would apply the RelativeLayout.LayoutParams to the editText by saying

    editText.setLayoutParams(rlp);

Simon
  • 19,658
  • 27
  • 149
  • 217