gpt4 book ai didi

android - 在 Nexus 4 中使用 admob/amazon 添加时查看扭曲/模糊

转载 作者:行者123 更新时间:2023-11-29 01:40:41 25 4
gpt4 key购买 nike

在 Nexus 4 中,当显示添加(admob 或亚马逊的)时,触摸屏幕添加和移动的 View 会变形。如果不显示广告,则 View 没有问题。在模拟器和 galaxy IV 中都没有任何问题。

我认为问题可能与 chrome 渲染器及其使用的 egl 驱动程序有关,但不知道如何解决。

使用 admob 的测试 View 代码:

public class TestAdmob extends ViewGroup {
private AdView adView;
private Rect drawRect;
private Test1 myView;

public TestAdmob(Activity context, String adUnitId) {
super(context);

myView = new Test1(context);
drawRect = new Rect(0, 0, 400, 400);

adView = new AdView(context);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(adUnitId);
adView.setAdListener(new AdListener() {
public void onAdLoaded() {
Log.d("Admob", "onAdLoaded");
requestLayout();
}
public void onAdFailedToLoad(int errorCode) { Log.d("Admob", "failedToLoad " + errorCode); }
public void onAdOpened() { Log.d("Admob", "adOpened"); }
public void onAdClosed() { Log.d("Admob", "adClosed"); }
public void onAdLeftApplication() { Log.d("Admob", "adLeftApp"); }
});
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();

addView(adView);

adView.loadAd(adRequest);

}

private int getHeightAd() {
try { return adView.getAdSize().getHeightInPixels(adView.getContext()); }
catch (Exception e) {
e.printStackTrace();
return 200;
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
adView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(getHeightAd(), MeasureSpec.EXACTLY));
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
adView.layout(l, 0, r, getHeightAd());
myView.layout(drawRect.left, drawRect.top, drawRect.right, drawRect.bottom);
}

@Override public boolean onTouchEvent(MotionEvent event) {
drawRect.offsetTo((int)event.getX()-drawRect.width()/2, (int)event.getY()-drawRect.height()/2);
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
addView(myView);
break;
case MotionEvent.ACTION_MOVE:
requestLayout();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_OUTSIDE:
removeView(myView);
default:
break;
}
return true;
}
private class Test1 extends View {
Path path = new Path();
Bitmap bitmap;

public Test1(Context context) {
super(context);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.anImage);
}


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
path.moveTo(0, 0);
path.lineTo(getWidth(), 0);
path.lineTo(getWidth()/2, getHeight());
path.moveTo(0, 0);
canvas.clipPath(path);

canvas.drawBitmap(bitmap, 0, 0, null); }

}
}

显示广告时的扭曲 View : distorted view

当不是时,它应该是:

good view

最佳答案

终于找到解决办法了。基于this post ,我修改了这样的代码(添加了 setLayer 行):

...
}

private class Test1 extends View {
Path path = new Path();
Bitmap bitmap;

public Test1(Context context) {
super(context);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable. anImage);
}
...

关于android - 在 Nexus 4 中使用 admob/amazon 添加时查看扭曲/模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24863032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com