johnjoshua
johnjoshua

Reputation: 25

android setrotation issue on fragment

I am having a problem running a simple setRotation on a linear layout that houses a fragment. Running on a galaxy S3 and ticking disable hardware overlays in developer options makes everything work really smoothly, without it, it causes only portions of the view to be displayed in a haphazard patch type display when in landscape.

The reason i am rotating the view and adjusting its layout parameters is because there is a list that i need to have visible with the items the user has selected even during screen rotation.

the view is displayed above a camera surface.

The xml layout of the view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/occasionsOptionsLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:gravity="top"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical" >

    <TextView
        android:id="@+id/whatOccasionTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.7"
        android:gravity="left"
        android:padding="8dp"
        android:text="@string/whatstheoccasion"
        android:textColor="@color/Black"
        android:textSize="@dimen/textMedium" />

    <ImageView
        android:id="@+id/occasionTitleImage"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_margin="2dp"
        android:layout_weight="0.3"
        android:padding="2dp"
        android:src="@drawable/mood" />
</LinearLayout>

<ScrollView
    android:id="@+id/occasionscrollView"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <fragment
            android:id="@+id/occasion_fragment"
            android:name="com.myapp.record.Occasions"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/occasionaOptionsClose"
    android:layout_width="fill_parent"
    android:layout_height="55dp"
    android:layout_gravity="center_vertical"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/occasionsOptionsCloseAction"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:src="@drawable/close" />
</LinearLayout>

</LinearLayout>

and the call to rotate the view:

 occasionsIncluder = (LinearLayout) findViewById(R.id.occasionIncluder);
occasionsIncluder.setRotation(rotateToValue);

rotateToValue is a simple call to the screen orientation value in degrees.

my question is why would disabling hardware overlays cause it to actually work better, i thought this option was to make things run smoother anyway?

Upvotes: 2

Views: 332

Answers (2)

johnjoshua
johnjoshua

Reputation: 25

setWillNotDraw() was the culprit

Upvotes: 0

Shobhit Puri
Shobhit Puri

Reputation: 26007

Q: why would disabling hardware overlays cause it to actually work better?

A: I want to direct you to the official android documentation on Hardware Acceleration. It says:

Because of the increased resources required to enable hardware acceleration, your app will consume more RAM.

If your application uses only standard views and Drawables, turning it on globally should not cause any adverse drawing effects. However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your applications that use custom views or drawing calls. Problems usually manifest themselves as invisible elements, exceptions, orwrongly rendered pixels.

To remedy this, Android gives you the option to enable or disable hardware acceleration at the following levels:

  • Application
  • Activity
  • Window
  • View

Hope this helps you understand the cause.For more, you can read through the link.

Upvotes: 2

Related Questions