java - Android: align_left aligns to the center -
i have fragment contains google map:
<com.google.android.gms.maps.mapview android:id="@+id/mapview" android:layout_width="match_parent" android:layout_height="match_parent" map:camerazoom="13" map:maptype="normal" map:uizoomcontrols="false" map:uirotategestures="true" map:uiscrollgestures="true" map:uizoomgestures="true" map:uitiltgestures="false" />
the map takes entire screen , has mylocation enabled:
map.setmylocationenabled(true);
the following code should align mylocation button top-left of screen:
// mylocation button view view locationbutton = ((view) mapview.findviewbyid(integer.parseint("1")).getparent()).findviewbyid(integer.parseint("2")); relativelayout.layoutparams rlp = (relativelayout.layoutparams) locationbutton.getlayoutparams(); rlp.addrule(relativelayout.align_parent_top); rlp.addrule(relativelayout.align_parent_left);
however - aligns button top center of screen. however, if add this:
if (build.version.sdk_int >= 17) { rlp.addrule(relativelayout.align_parent_start); }
then aligns left properly. problem align_parent_start can't used programmatically before api 17 , need support lower api level. why isn't align_parent_left working on it's own align button left?
here's implementation of moving location button:
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <framelayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_weight="1" android:name="com.google.android.gms.maps.supportmapfragment"> </fragment> . . .
on activity:
mapfragment = ((supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.mymap)); //if you're using fragment use: //mapfragment = ((supportmapfragment) getchildfragmentmanager() .findfragmentbyid(r.id.mymap)); mapfragment.getmapasync(new onmapreadycallback() { @override public void onmapready(googlemap googlemap) { //add map adjustments here// //then move location button view locationbutton = ((view) mapfragment.getview().findviewbyid(integer.parseint("1")). getparent()).findviewbyid(integer.parseint("2")); // , next place it, exemple, on bottom right (as google maps app) relativelayout.layoutparams rlp = (relativelayout.layoutparams) locationbutton.getlayoutparams(); // position on right bottom rlp.addrule(relativelayout.align_parent_top, 0); rlp.addrule(relativelayout.align_parent_bottom, relativelayout.true); rlp.setmargins(0, 0, 30, 30); } });
Comments
Post a Comment