Custom rotated EditText view with working selection, cursor location, etc

后端 未结 5 1365
感情败类
感情败类 2020-12-09 17:06

What I want to do

I want to make a rotated and flipped EditText view that has all of the properties of a normal EditText view.

My problem

I have

5条回答
  •  臣服心动
    2020-12-09 17:26

    Tried to get the partial solution with minor changes, check if that's you want.

    1) Set android:gravity="top|left" in your edittext declaration inside xml.

    2) Noticed that without super method call inside onDraw method, not able to show cursor. So I called,

    super.onDraw(canvas);
    

    instead,

    getLayout().draw(canvas);
    

    3) For touch events, I tried to swap x and y coordinates. So that you can have cursor as per touch event.(Just tried and it was working, got lucky :) )

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        event.setLocation(event.getY(), event.getX());
        return super.onTouchEvent(event);
    }
    

    Comment this line inside onDraw method, for exact touch event(Found by trial and error).

    canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
    

    4) I could not do any thing about highlighting or selecting text.

    ?) Another Solution : If you think that, some how you get RTL language support work on edittext then you just need to rotate it. But unfortunately its not working properly with android. Reference : How to handle RTL languages on pre 4.2 versions of Android? and Android setting with TextView for Hebrew text?

提交回复
热议问题