我正在尝试约束MapView的大小,使其占据屏幕高度的90%,并将剩余的10%留在底部以用于另一个视图,例如一个菜单栏。我可以获得效果,但菜单栏覆盖了MapView,因此地图的底部不可见。虽然MapView可以滚动,但Google徽标部分模糊(我怀疑这可能违反了Maps API的T& C),我宁愿限制MapView包含在屏幕的指定部分内。到目前为止,我还没有找到任何将MapView强制执行到正常布局约束的布局,例如layout_weight。
我开始认为这只能通过获取设备的屏幕尺寸以及然后明确设置MapView布局宽度和高度以编程方式实现,或者是否有人设法使用xml布局执行此操作。
答案 0 :(得分:1)
我找到了答案here。这基本上就是约翰所说的,使用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>