自Ice-Cream-Sandwich以来,有一个名为“强制GPU渲染”的开发者选项。如果启用它拒绝显示一些大的Drawables。因此,我想知道,如果启用此选项,则通知用户必须将其关闭,如果他想看到可绘制的话。
答案 0 :(得分:3)
找到一个您知道不应加速的视图,如果添加
,则该视图应为任何视图android:hardwareAccelerated="false"
到你的< application>在Android Manifest中,然后在您的代码中,调用
view.isHardwareAccelerated();
如果返回true,则将该选项设置为on。这已被证实适用于我的Galaxy Nexus。
答案 1 :(得分:2)
在Kai的帮助下,我在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();
}
}
}
}
}
答案 2 :(得分:0)
我不认为您可以通过添加
来关闭它android:hardwareAccelerated="false"
如果将代码追踪到Window.setWindowManager()中,则可以看到以下内容
public void setWindowManager(...) {
...
mHardwareAccelerated = hardwareAccelerated
|| SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
...
}
其中,
hardwareAccelerated:来自android:hardwareAccelerated
PROPERTY_HARDWARE_UI属性由“强制GPU渲染”选项设置。
您可以看到,如果用户手动选中“强制GPU渲染”选项,则无论android:hardwareAccelerated是什么,mHardwareAccelerated变量都将被赋值为TRUE值。