旋转一个TextView和重新测量在Android的
问题描述:
我试图创建一个具有以下代码旋转一个TextView和重新测量在Android的
public class VerticalTextView extends TextView{
public VerticalTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public VerticalTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public VerticalTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
Log.i("VerticalTextView", "onDraw Called");
canvas.save();
canvas.rotate(-90, getWidth()/2, getHeight()/2);
super.onDraw(canvas);
canvas.restore();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
super.setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
}
但是我发现,它没有重新定义新高度全宽垂直的TextView。因此文本真的被截断。
任何想法? 米
答
在这种similar question(看kostmo回答不接受一个),他使用了两个自定义的方法来计算视图(measureHeight
和measureWidth
)的大小。因为super.setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
根据他的回答看起来不对。
看来你还可以复制/粘贴他的答案,我认为这是你正在努力实现的。
非常感谢,不知道我错过了它! – mAndroid 2011-12-18 13:07:21