Android Google Map Fragment 1:1 ratio (Same height and width) -


i trying create google maps aspect ratio 1:1 height same width. current code:

<linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margin="10dp"         android:background="@drawable/border"         android:orientation="vertical"         android:paddingbottom="15dp"         android:paddingleft="15dp"         android:paddingright="15dp"         android:paddingtop="5dp">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="locatiegegevens"             android:textstyle="bold" />          ...          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="woonplaats:" />          <fragment xmlns:android="http://schemas.android.com/apk/res/android"             xmlns:map="http://schemas.android.com/apk/res-auto"             android:id="@+id/mappreview"             android:name="com.google.android.gms.maps.mapfragment"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margintop="5dp"             map:camerazoom="13"             map:litemode="true"              map:maptype="normal" />      </linearlayout> 

the fragment class:

public class casefragment extends fragment implements onmapreadycallback {  private googlemap mmap; private case caseobj;  private textview title;  public casefragment() {     // required empty public constructor }  public static casefragment newinstance(case caseobj) {     casefragment casefragment = new casefragment();      bundle args = new bundle();     args.putserializable("case", caseobj);     casefragment.setarguments(args);     return casefragment; }  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     bundle args = getarguments();     caseobj = (case) args.getserializable("case"); }  @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     // inflate layout fragment     view view = inflater.inflate(r.layout.fragment_case, container, false);      title = (textview) view.findviewbyid(r.id.txttitle);     title.settext(caseobj.getid());      mapfragment mapfragment = (mapfragment) getchildfragmentmanager().findfragmentbyid(r.id.mappreview);     mapfragment.getmapasync(this);       return view; }  @override public void onmapready(googlemap googlemap) {     latlng sydney = new latlng(-33.852, 151.211);     googlemap.addmarker(new markeroptions().position(sydney)             .title("marker in sydney"));     googlemap.movecamera(cameraupdatefactory.newlatlng(sydney)); } } 

i tried use layoutparams made width same height reason:

viewgroup.layoutparams params = mmapfragment.getview().getlayoutparams(); params.height = params.width; mmapfragment.getview().setlayoutparams(params); 

it looks this: enter image description here

use custom view class extended mapview instead of fragment

then, override onmeasure below

   @override     protected void onmeasure(int width, int height) {         // note applying width value height         super.onmeasure(width, width);     } 

it solve issue.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -