Làm cách nào để hiển thị văn bản lộn ngược với chế độ xem văn bản trong Android?Làm cách nào để hiển thị văn bản lộn ngược với chế độ xem văn bản trong Android?
Trong trường hợp của tôi, tôi có trò chơi 2 người chơi, nơi họ chơi với nhau. Tôi muốn hiển thị bài kiểm tra cho người chơi thứ hai được định hướng cho họ.
Đây là giải pháp tôi thực hiện sau khi AaronMs lời khuyên
Lớp mà không được trọng, bab.foo.UpsideDownText
package bab.foo;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextView;
public class UpsideDownText extends TextView {
//The below two constructors appear to be required
public UpsideDownText(Context context) {
super(context);
}
public UpsideDownText(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public void onDraw(Canvas canvas) {
//This saves off the matrix that the canvas applies to draws, so it can be restored later.
canvas.save();
//now we change the matrix
//We need to rotate around the center of our text
//Otherwise it rotates around the origin, and that's bad.
float py = this.getHeight()/2.0f;
float px = this.getWidth()/2.0f;
canvas.rotate(180, px, py);
//draw the text with the matrix applied.
super.onDraw(canvas);
//restore the old matrix.
canvas.restore();
}
}
Và đây là cách bố trí XML của tôi:
<bab.foo.UpsideDownText
android:text="Score: 0"
android:id="@+id/tvScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
>
</bab.foo.UpsideDownText>
Hrm Khi tôi hỏi câu hỏi này không có sẵn. Tôi đã trên 1,6 bạn có biết nếu điều này đã được thêm vào một bản phát hành sau này? – Ravedave
Chỉ có sẵn trong API 11+ – AndroidDev
Hãy dùng thử Ứng dụng của tôi bị lỗi, –