Creating oblique edittext in android

2019-06-09 11:15发布

I have a requirement to show an EditText at 45 degree angled to horizontal axis.So I used this code to do this

EditText editText = (EditText) findViewById(R.id.edit_text);
editText.setText("Hello");
Animation anim = new RotateAnimation(0.0f, -45.0f, 190, 90);
anim.setFillAfter(true);
editText.setAnimation(anim);

It also shows the EditText as per my requirement. But problem arises when I started typing some text in it.

Screen Shot

As you can see the screen shot, some places of the edittext are not showing the text and at the middle portion of the edittext is only displaying the text.

The Hello which is in the left corner of the edittext is just becase of, I set that using setText()

Please help me how to create an edittext obliquely so that I can type properly in it.

1条回答
Animai°情兽
2楼-- · 2019-06-09 11:26

After a long R&D, I succeed in solving this,

public class CustomEditText extends EditText {

private Animation rotateAnim;
public CustomEditText(Context context) {
        super(context);
}

public CustomEditText(Context context, AttributeSet attrs){
    super(context, attrs);
}

private void createAnim(Canvas canvas) {
        rotateAnim = new RotateAnimation(0, -45, 250, 50);
        rotateAnim.setRepeatCount(Animation.INFINITE);
        startAnimation(rotateAnim);
}

@Override
protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // creates the animation the first time
        if (rotateAnim == null) {
                createAnim(canvas);
        }

}
}

My new working screen shot

查看更多
登录 后发表回答