2013-05-27 28 views
2

對不起,可能是一個愚蠢的問題。 我有一個問題,運行一個簡單的setRotation線性佈局,其中包含一個片段。 在Galaxy S3上運行,並在開發人員選項中勾選禁用硬件覆蓋層,可以使所有工作都非常順利地進行,沒有它,它會導致只有部分視圖在橫向顯示爲雜亂無章的補丁類型顯示。Android setrotation probem片段

我旋轉視圖並調整其佈局參數的原因是因爲有一個列表,我需要用戶在屏幕旋轉期間選擇的項目可見。

視圖顯示在攝像機表面上方。

視圖的XML佈局:

<?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> 

和旋轉視圖呼叫:

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

rotateToValue是在度屏幕方向值的簡單呼叫。

我的問題是爲什麼禁用硬件覆蓋會導致它實際上運行得更好,我認爲這個選項是爲了讓事情運行更流暢嗎?

非常感謝。

回答

2

問:爲什麼禁用硬件覆蓋會使它實際上效果更好?

- 答:我想引導你到Hardware Acceleration官方android文檔。 它說:

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, or錯誤地渲染的像素

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

  • 應用
  • 活動
  • 窗口
  • 查看

希望這有助於你瞭解cause.For更多,您可以通過鏈接閱讀。

+0

Shobhit謝謝你的答案。 我先看了一遍,然後用android:hardwareAccelerated =「true」和false處理了清單中的運動。 沒有幫助。 我能讓它正常工作的唯一方法是在開發人員選項中勾選選項,如我在文章中提到的那樣。 這是今天買來的全新手機,我老S3收拾起來。 – johnjoshua

+0

歡迎你的朋友!您試圖在哪個級別啓用硬件加速? –

+0

嗯,我基本上從應用程序到活動的方式來查看。 一切檢查出來好吧,直到我在視圖上調用.setRotation,它變成梨形。 我在這裏接近這個錯誤的方式嗎?凌晨3點,無言! – johnjoshua