2012-03-14 27 views
2

由於冰淇淋三明治有一個名爲「強制GPU渲染」的開發人員選項。如果啓用,它拒絕顯示一些大的Drawables。因此,如果啓用此選項,我想知道如果要查看該可繪製對象,則必須通知用戶必須將其關閉。找出是否啓用「強制GPU渲染」

回答

3

取景,你知道不應該加速,這應該是沒有什麼查看,如果你在Android清單添加

android:hardwareAccelerated="false" 

您<應用>,然後在你的代碼,調用

view.isHardwareAccelerated(); 

如果它返回true,則該選項設置爲on。這已經被證實可以在我的Galaxy Nexus上運行。

2

在凱的幫助下,我在android-developers上發現了這個Hardware Acceleration話題。不幸的是,我們想保持與2.1的兼容性,所以我爲任何有類似問題的人添加我的解決方案。因此,一個活動中:

public View contentView 

public void onCreate(Bundle savedInstanceState){ 

    contentView = findViewById(R.id.someId); 
    //initialize Views ... 
    setContentView(contentView); 

    //use a handler as easiest method to post a Runnable Delayed. 
    //we cannot check hardware-acceleration directly as it will return reasonable results after attached to Window. 
    Handler handler = new Handler(); 
    handler.postDelayed(HardwareAccelerationRunnable(), 500); 
} 

public class HardwareAccelerationRunnable implements Runnable{ 
    public void run(){ 
    //now lets check for HardwareAcceleration since it is only avaliable since ICS. 
    // 14 = ICS_VERSION_CODE 
    if (android.os.Build.VERSION.SDK_INT >= 14){ 
     try{ 
      //use reflection to get that Method 
      Method isHardwareAccelerated = contentView.getClass().getMethod("isHardwareAccelerated", null); 
      Object o = isHardwareAccelerated.invoke(contentView, null); 
      if (null != o && o instanceof Boolean && (Boolean)o){ 
       //ok we're shure that HardwareAcceleration is on. 
       //Now Try to switch it off: 
       Method setLayerType = contentView.getClass().getMethod("setLayerType", int.class, android.graphics.Paint.class); 
       setLayerType.invoke(contentView, 1, null); 
      } 
     } catch(Exception e){ 
      e.printStackTrace(); 
     } 

    } 
    } 
} 



} 
+0

我的應用程序的minSdk版本是7,我的應用程序與ICS相比,在3.0以下的版本上運行平穩,因爲min sdk是7,所以我想以編程方式打開gpu渲染選項,如果它尚未啓用。如果相同的apk用於ICS,我該怎麼做? – 2012-04-25 07:12:18

+1

請記住,我想在應用程序級別啓用渲染,而不是在視圖級別。 – 2012-04-25 09:15:28

0

我不認爲你可以通過添加

android:hardwareAccelerated="false" 

如果您跟蹤代碼到Window.setWindowManager()關閉它,你可以看到下面的

public void setWindowManager(...) { 
... 
mHardwareAccelerated = hardwareAccelerated 
       || SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false); 
... 
} 

其中,

硬件加速:來自安卓的硬件加速

PROPERTY_HARDWARE_UI屬性由「強制GPU渲染」選項設置。

您可以看到,如果用戶手動檢查「強制GPU渲染」選項,無論android:hardwareAccelerated是什麼,mHardwareAccelerated變量都將分配一個TRUE值。