我有一个横向模式的 Activity 。里面有一个像这样对齐的 Custom-Title-View:
是否可以保持横向模式并将这个 View “伪造”为纵向模式,如下所示:
我试图覆盖我的自定义 TitleView 并将类似这样的内容添加到 draw(Canvas)
public class VerticalTitle extends Title{
public draw(Canvas){
canvas.save();
canvas.rotate(getWidth() / 2, getHeight() / 2);
// i tryed many translations, but get none to work
canvas.translate(0, getHeight());
super.draw(canvas);
canvas.restore()
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
}
如果有任何兴趣,TitleBar 从 RelativeLayout 扩展并具有固定的高度和 fill_parent 宽度
View 中的 setRotate 参数不是一个选项,因为应用程序应该与 2.2 保持兼容。
最佳答案
您必须先扩展 TextView 并构建您的自定义垂直 TextView ,请先查看这两个链接以获取更多详细信息
然后在您的布局区域中,您可以将此 Xml 文件用于您的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.yourpackage.CustomVerticalTextView
android:layout_width="42dp"
android:layout_height="fill_parent"
android:text="@string/hello"
android:background="#0000FF" />
</LinearLayout>
如果您想旋转布局而不是将其所有子项旋转 90 度,请使用 布局动画 Controller
看这个SO thread了解更多详情
关于android - 在横向模式下将 View 伪造为纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816096/