2011-12-18 19 views
0

我試圖創建一個具有以下代碼旋轉一個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。因此文本真的被截斷。

任何想法? 米

回答

0

在這種similar question(看kostmo回答不接受一個),他使用了兩個自定義的方法來計算視圖(measureHeightmeasureWidth)的大小。因爲super.setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());根據他的回答看起來不對。

看來你還可以複製/粘貼他的答案,我認爲這是你正在努力實現的。

+0

非常感謝,不知道我錯過了它! – mAndroid 2011-12-18 13:07:21