Creating oblique edittext in android

為{幸葍}努か 提交于 2019-12-23 05:43:49

问题


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.

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:


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);
        }

}
}



来源:https://stackoverflow.com/questions/11035976/creating-oblique-edittext-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!