Android: Make multiline edittext scrollable, disable in vertical scroll view

后端 未结 3 638
春和景丽
春和景丽 2021-01-06 15:41

I am developing an application in which i am struct at a point.

As according to my application requirement i created horizontal scrollview in xml and then vertical s

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-06 16:20

    You can do one thing.

    Just make edit text focusable false. And apply on touch listener.

    So user is not able to edit text and it will scroll as:

    EditText editText = new EditText(this);
    editText.setId(1);
    editText.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,0f));
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    editText.setGravity(Gravity.TOP|Gravity.LEFT);
    editText.setHint("Comment");
    editText.setSingleLine(false);
    editText.setLines(5);
    editText.setMaxLines(5);
    editText.setText(CommentFromDB);
    editTextRemark.setFocusable(false);
    

    Apply onTouchListner as:

    editTextRemark.setOnTouchListener(touchListener);
    

    and

    OnTouchListener touchListener = new View.OnTouchListener(){
        public boolean onTouch(final View v, final MotionEvent motionEvent){
            if(v.getId() == 1){
                v.getParent().requestDisallowInterceptTouchEvent(true);
                switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
                    case MotionEvent.ACTION_UP:
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }
            }
            return false;
        }
    };
    

    Hope this answer will help you.

提交回复
热议问题