Android change google map padding at runtime

陌路散爱 提交于 2019-11-27 17:46:43

问题


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);
    }
});

回答1:


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());
        }
    });


来源:https://stackoverflow.com/questions/22267814/android-change-google-map-padding-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!