问题描述
因此,继承人的交易。我想提出一个游戏andEngine我用克罗马presoltionpolicy(它的工作原理:的)。我有引擎的相机设定为480×800的水平方向。但是设备的分辨率为1920×1080。在我的游戏屏幕顶部和底部的部分溢出的设备屏幕(见previous链接的画面,怎么红色矩形四溢的左侧和右侧)。所以,当我想补充的旗帜,直接在上面(对齐的主游戏活动布局的顶部)启动其部分hiddden。我可以伊斯利移动横幅低一点只需使用'.setY(),但在其他设备上使用不同的屏幕,不能正常工作。因此,我正在寻找的是一个方法,在顶部或设备屏幕,而不是游戏查看/布局的底部总是设置的旗帜,因为他们是不一样的。
我的,我用它来显示广告code:
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
最后DisplayMetrics displayMetrics =新DisplayMetrics();
。this.getWindowManager()getDefaultDisplay()getMetrics(displayMetrics)。
this.adView =新的AD浏览报(本);
this.adView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
this.adView.setAdUnitId(myAdId);
com.google.android.gms.ads.AdRequest adrequest =新com.google.android.gms.ads.AdRequest.Builder().addTestDevice(com.google.android.gms.ads.AdRequest.DEVICE_ID_EMULATOR).build();
this.adView.setY(displayMetrics.heightPixels - this.adView.getHeight()); //这里我把我的旗帜的位置,但它不能正常工作
this.adView.loadAd(adrequest);
RelativeLayout的布局=(RelativeLayout的)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams PARAMS =新RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.addView(this.mRenderSurfaceView);
layout.addView(this.adView,则params);
}
我的main_activity.xml:
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:重力=中心
工具:上下文=com.hsdev.salesrep.MainActivity>
< / RelativeLayout的>
貌似答案是很容易的,如果你觉得够了:
最后DisplayMetrics displayMetrics =新DisplayMetrics();
this.adView.setY(displayMetrics.heightPixels - (this.adView.getHeight()*(displayMetrics.heightPixels / 480)) - 50);
其中,480是照相机的andEngine高度和50是你的旗帜的高度。
So heres the deal. I am making a game in andEngine and I use CropResoltionpolicy (how it works: http://android.kul.is/2013/10/andengine-tutorial-dealing-with-screen-sizes.html). I have engine camera set as 480x800 in horizontal orientation. but the devices resolution is 1920x1080. In my game top and bottom parts of the screen are overflowing devices screen (see the previous link, how red rectangles are overflowing on left and right of the screen). So when I add banner that starts directly on top (aligned to the top of the main game activity layout) it is partially hiddden. I can easly move banner a bit lower just by using '.setY()' but that does not work properly on other devices with different screens. So what I'm looking for is a method to set the banner always on top or bottom of the devices screen, not game view/layout because they are not the same.
My code that I use to show ads:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final DisplayMetrics displayMetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
this.adView = new AdView(this);
this.adView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
this.adView.setAdUnitId("myAdId");
com.google.android.gms.ads.AdRequest adrequest = new com.google.android.gms.ads.AdRequest.Builder().addTestDevice(com.google.android.gms.ads.AdRequest.DEVICE_ID_EMULATOR).build();
this.adView.setY(displayMetrics.heightPixels - this.adView.getHeight()); // here I set position of my banner, but it does not work properly
this.adView.loadAd(adrequest);
RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.addView(this.mRenderSurfaceView);
layout.addView(this.adView, params);
}
My main_activity.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id ="@+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
tools:context="com.hsdev.salesrep.MainActivity" >
</RelativeLayout>
Looks like answer is easy enough if you think enough:
final DisplayMetrics displayMetrics = new DisplayMetrics();
this.adView.setY(displayMetrics.heightPixels - (this.adView.getHeight() * (displayMetrics.heightPixels / 480) ) - 50);
where 480 is a height of camera in andEngine and 50 is a height of your banner.
这篇关于如何在使用andEngine克罗马presolutionPolicy恰好在屏幕的底部显示admob的smartbanner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!