Reputation: 185
Looked around for an answer to this but can only find others with the same problem and no resolution. I am trying to rotate a regular SherlockFragment inflated with a very simple layout (just for test purposes):
<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>
The fragment code:
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;
}
This will rotate the view about the pivot in the middle but will not change the layout to the correct bounds. The best that I have managed to do is to setPivotX(size.x/2) and setPivotY(size.x/2) with size.x being the screen width of the device and setLayoutParams(size.y, size.y). This kind of works in that it creates a square the size of the fragment but runs off the width due to it being set to size.y not x however setLayoutParams(size.x, size.y) just creates half a square...and bizarrely so does setLayoutParams(size.y, size.x).
Does anyone have any resolution to this where the fragment will resize to the correct x and y co-ordinates to fill the screen after the whole fragment is rotated?
Upvotes: 1
Views: 1349
Reputation: 185
In the FrameLayout holder in the activity xml I set:
android:clipChildren="false"
I then used translationX and translationY on the rotated view to move it into position and viola it worked. I would say this in essence is a bug in Android, after rotation, the clipping bounds for width and height remain the same but should be swapped.
Upvotes: 2