Android在运行时更改Google地图填充 [英] Android change google map padding at runtime
问题描述
我想在运行时移动Google地图布局项目,但我无法做到,但我不知道它是否可行。
我想要做的是:我有一个Google地图片段,占据了所有的屏幕。我也有一个广告。当应用程序启动时,我会显示地图。像这样:
当广告加载时,我会在底部展示广告,但我需要将Google徽标移到广告上方。像这样:
我尝试过:
if(banner is loaded)
googleMap.setPadding(0,0,0,banner.getLayoutParams()。height);
但我没有成功。我做错了什么?
编辑: 感谢@SimplePlan,我改变了RelativeLayout, mapfragment转换为FrameLayout:
< FrameLayout>
< fragment
android:id =@ + id / map
class =com.google.android.gms.maps.SupportMapFragment/>
< com.inmobi.monetization.IMBanner
android:layout_gravity =bottom/>
< / FrameLayout>
我在广告中加入了一位监听者:
banner.setIMBannerListener(new IMBannerListener(){
@Override
public void onBannerRequestSucceeded(IMBanner arg0){
googleMap.setPadding(0,0 ,0,banner.getLayoutParams()。height);
}
});
只要布局过程没有完成, view的维度设置为0.使用 Handler
,您可以在布局完成后设置地图的填充。
<$ p (){
@Override
public void run(){
mapHelper.map.setPadding(0,0) ,0,ad.getHeight());
}
});
I want to move Google map layout items at runtime, but I'm not able to do it and I don't know if it's possible or not. What I want to do is: I have a Google map fragment which takes up all the screen. I also have an Ad. When app starts, I show the map. Like this:
And when the ad loads, I show the ad at the bottom, but I need to move the Google logo above the ad. Like this:
I've tried with:
if (banner is loaded)
googleMap.setPadding(0, 0, 0, banner.getLayoutParams().height);
But I had no success. What am I doing wrong?
EDIT: Thanks to @SimplePlan, I changed the RelativeLayout where was included the mapfragment to a FrameLayout:
<FrameLayout >
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment" />
<com.inmobi.monetization.IMBanner
android:layout_gravity="bottom" />
</FrameLayout>
And I added a listener to the Ad:
banner.setIMBannerListener(new IMBannerListener() {
@Override
public void onBannerRequestSucceeded(IMBanner arg0) {
googleMap.setPadding(0, 0, 0, banner.getLayoutParams().height);
}
});
As long as the layout process is not finished, the view's dimension is set to 0. Using Handler
, you can set the map's padding after the layout is done.
new Handler().post(new Runnable() {
@Override
public void run() {
mapHelper.map.setPadding(0,0,0,ad.getHeight());
}
});
这篇关于Android在运行时更改Google地图填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!