自从Ice-Cream-Sandwich以来,有一个开发者选项叫做“强制GPU渲染”。如果启用,它将拒绝显示某些较大的Drawables。因此,我想知道,如果此选项被启用,以通知用户他必须关闭它,如果他想要看到该绘图。
发布于 2012-03-14 23:45:35
找到一个你知道不应该加速的视图,如果你添加了
android:hardwareAccelerated="false"添加到Android Manifest中,然后在代码中调用
view.isHardwareAccelerated();如果返回true,则选项设置为on。这已被确认可以在我的Galaxy Nexus上工作。
发布于 2012-03-15 08:15:49
在Kai的帮助下,我在android上找到了这个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();
}
}
}
}
}发布于 2013-03-05 18:44:55
我不认为你可以通过添加
android:hardwareAccelerated="false"如果将代码跟踪到Window.setWindowManager()中,您可以看到以下内容
public void setWindowManager(...) {
...
mHardwareAccelerated = hardwareAccelerated
|| SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
...
}哪里,
hardwareAccelerated:来自安卓:硬件加速
PROPERTY_HARDWARE_UI属性是通过"Force GPU rendering“选项设置的。
你可以看到,如果用户手动勾选“强制GPU渲染”选项,无论android:hardwareAccelerated是什么,mHardwareAccelerated变量都会被赋予一个真实值。
https://stackoverflow.com/questions/9704946
复制相似问题