环顾四周寻找答案,但只能找到其他有相同问题且没有解决方案的人。我正在尝试旋转一个普通的 SherlockFragment,它的布局非常简单(仅用于测试目的):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/jan"
android:textColor="@color/standard_text_color"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
片段代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View result = inflater.inflate(R.layout.foo_layout, null);
result.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
result.setRotation(90);
return result;
}
这将围绕中间的枢轴旋转视图,但不会将布局更改为正确的边界。我设法做的最好的事情是 setPivotX(size.x/2) 和 setPivotY(size.x/2),其中 size.x 是设备的屏幕宽度,setLayoutParams(size.y, size.y)。这种工作方式是它创建了一个片段大小的正方形,但由于它被设置为 size.y 而不是 x 而超出了宽度,但是 setLayoutParams(size.x, size.y) 只创建了半个正方形......奇怪的是 setLayoutParams(size.y, size.x) 也是如此。
有没有人对此有任何解决方案,在整个片段旋转后片段将调整为正确的 x 和 y 坐标以填充屏幕?