How do you programmatically change the width & height of Google Maps v2 (support Fragment)?

前端 未结 4 1289
清歌不尽
清歌不尽 2020-12-17 09:43

How do you programatically change the width and height of a com.google.android.gms.maps.SupportMapFragment? I\'d imagine you might be able to wrap it in a viewgroup with mat

相关标签:
4条回答
  • 2020-12-17 10:06

    Fastest (with less code lines) way i found:

    ViewGroup.MarginLayoutParams parms = (ViewGroup.MarginLayoutParams) rlLocation.getLayoutParams();
        parms.bottomMargin = 100;
        parms.topMargin = 100;
    
    0 讨论(0)
  • 2020-12-17 10:22

    You should not fix height of a map... set it according to screen height & width.

    DisplayMetrics displaymetrics = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            int height = displaymetrics.heightPixels;
    
            ViewGroup.LayoutParams params = mMapFragment.getView().getLayoutParams();
            params.height = height/2;
            mMapFragment.getView().setLayoutParams(params);
    
    0 讨论(0)
  • 2020-12-17 10:26

    I figured it out largely with the help of Programmatically set google map fragment visibility (API2).

    mMapFragment = (SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.storefront_map));
    ViewGroup.LayoutParams params = mMapFragment.getView().getLayoutParams();
    params.height = 900;
    mMapFragment.getView().setLayoutParams(params);
    
    0 讨论(0)
  • 2020-12-17 10:29

    this is an example using onConfigurationChanged() method :

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.main);
        findViewById(R.id.storefront_map).getLayoutParams().width = 400;
    }
    
    0 讨论(0)
提交回复
热议问题