9

I have an EditText, which generally shows parallel to the screen X-axis. I want to show it obliquely (around 45 degree to horizontal axis). Is it possible to do this in Android. Please guide me in a direction so that I can try for it.

After getting the two links in the answer by pawelzeiba, I proceed a little bit in solving this, but stuck again so I put another question on this. here is the link.

As Gunnar Karisson said, there is a setRotation() method in View class introduced in Android 3.0, but I cannot use it as my application should work fro Android 2.1 version.

So please help me to solve this.

Community
  • 1
  • 1
Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125

4 Answers4

3

EditText is an indirect subclass of View which has a rotation field you can set with setRotation(float):

myEditText.setRotation(45.0f).

Gunnar Karlsson
  • 28,350
  • 10
  • 68
  • 71
  • Gunnar, I cannot use this method as my app should run from Android 2.1 version onward. So I need some solution which could work on Android 2.1 version. See my edited question. – Chandra Sekhar Jun 21 '12 at 09:39
1

After a long R & D, I succeed to solve this by creating my own custom edittext, which works perfectly as per my requirement.

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

}
}
Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
0

You can rotate view, examples:

Vertical (rotated) label in Android
Is it possible to write vertically in a textview in android?

But I'm not sure how it will look with EditText during edition.

Community
  • 1
  • 1
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
0

If the setRotation() method isn't available to the API level you are working with, then your best bet would be to create your own subclass of View and implement a setRotation() method.

telkins
  • 10,440
  • 8
  • 52
  • 79
  • Thats what I am asking, I have already implemented but facing some problems in that case. Please see the link given in the question. – Chandra Sekhar Jun 21 '12 at 16:24