【发布时间】:2012-03-31 02:07:12
【问题描述】:
由于 Ice-Cream-Sandwich 有一个开发者选项,称为“强制 GPU 渲染”。如果启用,它会拒绝显示一些大的 Drawable。因此,我想知道,如果启用了此选项,则通知用户他必须将其关闭,如果他想查看该可绘制对象。
【问题讨论】:
标签: android rendering gpu android-4.0-ice-cream-sandwich
由于 Ice-Cream-Sandwich 有一个开发者选项,称为“强制 GPU 渲染”。如果启用,它会拒绝显示一些大的 Drawable。因此,我想知道,如果启用了此选项,则通知用户他必须将其关闭,如果他想查看该可绘制对象。
【问题讨论】:
标签: android rendering gpu android-4.0-ice-cream-sandwich
找到一个你知道不应该加速的视图,如果你添加它应该是任何视图
android:hardwareAccelerated="false"
到您的
view.isHardwareAccelerated();
如果它返回 true,则该选项设置为 on。这已被证实适用于我的 Galaxy Nexus。
【讨论】:
在 Kai 的帮助下,我在 android-developers 上找到了这个 Hardware Acceleration 主题。不幸的是,我们希望与 2.1 保持兼容,所以我为遇到类似问题的任何人添加了我的解决方案。所以在一个Activity里面:
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();
}
}
}
}
}
【讨论】:
我不认为你可以通过添加来关闭它
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 值。
【讨论】: