0
我的应用程序需要在可滚动的日历视图内旋转文本视图。问题是滚动内部布局后,它绕过边缘。旋转静态Textview很简单,但我该如何解决这个绘图问题?谢谢!Android自定义TextView忽略布局的边缘
我的自定义的TextView代码是:
public class VerticalTextView extends TextView {
final boolean topDown;
public VerticalTextView(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(getWidth(), 0);
canvas.rotate(90);
} else {
canvas.translate(0, getHeight());
canvas.rotate(-90);
}
canvas.clipRect(0, 0, getWidth(), getHeight(),
android.graphics.Region.Op.REPLACE);
super.draw(canvas);
}
}
使用: View.setRotation(270);
或View.setRotation(-90);
浅灰色区域是TextView的。正如你所看到的,它并没有延伸到整个白色区域。
关于将minSdkVersion增加到11(或者真的15,因为11-14基本上没有用户)的影响,请查看此控制面板:http://developer.android.com/about/dashboards/index。 html –
至于多行问题,请尝试在'TextView'上启用'android:singleLine =“true”'。 –
我minSdkVersion不是11 @Daniel Lew,我必须检查他的变化的影响。但是当我使用View.setRotation()时,文本往往会占用多行,像我的TextView这样的接缝并没有使用所有的空间。 –