Layout to constrain size of MapView

流过昼夜 提交于 2019-12-12 06:36:12

问题


I'm trying to constrain the size of a MapView so that it takes up, say 90% of the screen's height and leaves the remaining 10% at the bottom for another view e.g. a menu bar. I can get the effect but the menu bar overlays the MapView so that the bottom part of the map is not visible. Although the MapView can scroll the Google logo is partly obscured (and I suspect this might be against the T & C's of the Maps API), I'd rather constrain the MapView to be contained within a designated part of the screen. So far I haven't found any layout which enforces the MapView to the normal layout constraints e.g. layout_weight.

I'm beginning to think that this can only be achieved programatically by getting the device's screen dimensions and then explicitly setting the MapView layout width and height or has anyone managed to do this with an xml layout.


回答1:


I found the answer here. It is basically what John said, use layout_weight:

<LinearLayout ... >
 <FrameLayout android:id="@+id/map_frame"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="0.7" >     

    <com.google.android.maps.MapView
        android:id="@+id/map_view" 
        android:layout_width="fill_parent"
        android:layout_height="match_parent" 
        android:enabled="true" 
        android:clickable="true"             
        android:apiKey="api_key"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
 </FrameLayout>
</LinearLayout>



来源:https://stackoverflow.com/questions/6286055/layout-to-constrain-size-of-mapview

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