will it be possible to display text in diagonal way if yes then how can we implement, please help me out for this thanks. i have added image i have to replace WORLD text with other text.
Asked
Active
Viewed 2,841 times
0
-
its better if your use image with already written text. – Pankaj Arora Jul 03 '14 at 17:29
-
i have to set text as todays date which is not a good idea to put 365 images inside application..:( – chet's Jul 03 '14 at 17:32
-
agreed,but rotation won't works for all versions. – Pankaj Arora Jul 03 '14 at 17:36
-
yes that why i created custom text view class its working well with 4.0 os and also test on 2.3 OS working fine. – chet's Jul 03 '14 at 18:09
4 Answers
1
Look here: How to Rotate TextView 90 Degrees and display.
The easiest way to do this is to:
- Create
TextView
with your background image. - Rotate
TextView
as it is done in link above.
1
If you are using API 11 or later, you may try:
TextView tv = (TextView) findViewById(R.id.txtview);
String txt = "Stackoverflow";
tv.setText(txt);
tv.setRotation(45); // 45 degree rotation
Try this..

Lal
- 14,726
- 4
- 45
- 70
0
Use android:rotation in XML
or
textView.setRotation(angle)
http://developer.android.com/reference/android/view/View.html#attr_android:rotation

AndroidDev
- 5,193
- 5
- 37
- 68
-1
Guys i have implemented with custom textview thanks for your valuable response.working well on 4.0 device need to test it on 2.2 device.
public class DiagonalTextView extends TextView{
final boolean topDown;
public DiagonalTextView(Context context, AttributeSet attrs){
super(context, attrs);
final int gravity = getGravity();
if(Gravity.isVertical(gravity) && (gravity&Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
setGravity((gravity&Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP);
topDown = false;
}else
topDown = true;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
@Override
protected boolean setFrame(int l, int t, int r, int b){
return super.setFrame(l, t, l+(b-t), t+(r-l));
}
@Override
public void draw(Canvas canvas){
if(topDown){
canvas.translate(getHeight(), 0);
canvas.rotate(45);
}else {
canvas.translate(0, getWidth());
canvas.rotate(-45);
}
canvas.clipRect(0, 0, getWidth(), getHeight(), android.graphics.Region.Op.REPLACE);
super.draw(canvas);
}
}

chet's
- 193
- 2
- 8
-
while not mandatory, I believe it is a goodwill to value the original writer http://stackoverflow.com/a/19834048/1567541 – Hendra Anggrian Feb 22 '16 at 20:05