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());
}
});
来源:https://stackoverflow.com/questions/22267814/android-change-google-map-padding-at-runtime