adr*_*n54 6 android android-image cordova
我正在Android上用HTML/JS构建一个小游戏.我在HTC Desire(Android 2.2)上遇到了问题.当我触摸屏幕时,所有图像看起来都是像素化的,并且当触摸结束时它们会变得不像素化.
这是一个截图:

在右边是触摸屏幕的时候.有人可以帮我找出造成这个问题的原因吗?
笔记:
据我所知,“像素化”行为是针对滚动所做的优化(在 Froyo 及以上版本中)。如果渲染被简化,那么像滑动滚动动画这样的事情就需要更少的处理。
如果您需要完整的浏览器功能,我不确定您能提供多大帮助。
不过,既然你说你正在制作游戏,我可能有一个解决方法。我希望你的游戏不需要滚动(一个全屏),所以滚动优化是没有必要的。
我用 WebView 做了一个简单的测试。正如您所提到的,点击后,渲染会被简化,并且事情看起来有点不对劲。然后,一旦单击某些内容(WebView 知道不再发生滚动),事情就会恢复正常。
我通过用 FrameLayout 替换 WebView 来修改我的布局。FrameLayout 包含 WebView 和一个不可见的 Button(位于顶部)。该按钮捕获所有触摸事件。然后,我有选择地选择 WebView 应该需要什么类型的事件,并将它们传递给 WebView。如果触地和触地发生的时间很近,中间没有任何移动,就没有滚动的理由,所以我没有看到任何“像素化”行为。
因为这个示例最简单,所以我选择检测“MotionEvent.ACTION_UP”事件,当它完成时,我首先发送一个向下的事件,以便它模拟真实的点击。您当然可以在 ACTION_DOWN 上触发,但如果用户滑动或其他操作,您会得到不止一个,而且我想让这里的逻辑保持简单。您可以根据需要进行自定义,并且可能需要足够的工作,甚至在某些情况下启用滚动。我希望下面的代码足以传达我认为有效的内容。
WebView wv = new WebView(this);
View dummyView = new Button(this);
dummyView.setBackgroundColor(0x00000000);
dummyView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
MotionEvent down = MotionEvent.obtain(100, 100,
MotionEvent.ACTION_DOWN, event.getX(),
event.getY(), 0);
wv.onTouchEvent(down);
wv.onTouchEvent(event);
}
return false;
}
});
FrameLayout fl = new FrameLayout(this);
fl.addView(wv);
fl.addView(dummyView);
topLayout.addView(fl);
Run Code Online (Sandbox Code Playgroud)
编辑:如果您不想编辑 PhoneGap 源代码,您也许可以执行以下操作来更改 PhoneGap 布局...它未经测试,但似乎应该有效:
@Override
public void onCreate(Bundle arg0) {
super.onCreate(arg0);
super.loadUrl("file:///android_asset/www/index.html");
// Get the "root" view from PhoneGap
LinearLayout droidGapRoot = super.root;
// Create a new "root" that we can use.
final LinearLayout newRoot = new LinearLayout(this);
for (int i = 0; i < droidGapRoot.getChildCount(); i++) {
// Move all views from phoneGap's LinearLayout to ours.
View moveMe = droidGapRoot.getChildAt(i);
droidGapRoot.removeView(moveMe);
newRoot.addView(moveMe);
}
// Create an invisible button to overlay all other views, and pass
// clicks through.
View dummyView = new Button(this);
dummyView.setBackgroundColor(0x00000000);
dummyView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Only pass "UP" events to the specific view we care about, but
// be sure to simulate a valid "DOWN" press first, so that the
// click makes sense.
if (event.getAction() == MotionEvent.ACTION_UP) {
MotionEvent down = MotionEvent.obtain(100, 100,
MotionEvent.ACTION_DOWN, event.getX(),
event.getY(), 0);
newRoot.onTouchEvent(down);
newRoot.onTouchEvent(event);
}
return false;
}
});
// Layer the views properly
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(newRoot);
frameLayout.addView(dummyView);
// Add our new customized layout back to the PhoneGap "root" view.
droidGapRoot.addView(frameLayout);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1198 次 |
| 最近记录: |