【问题标题】:Adding a custom view to the mapview that does not move with the map view向不随地图视图移动的地图视图添加自定义视图
【发布时间】:2016-12-15 13:51:49
【问题描述】:

我想在地图视图上添加一个视图,当我移动地图视图时它不会移动。地图视图可以放大或缩小,但视图应该固定在地图视图的中心。请指导我如何操作。

谢谢

【问题讨论】:

  • 我需要以编程方式而不是通过 xml。
  • 发布你的一些代码

标签: android google-maps android-custom-view android-mapview


【解决方案1】:

这应该是你的 xml 代码

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </RelativeLayout>

然后在您的活动中执行此操作

RelativeLayout.LayoutParams layoutParams = new
    RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
relativeLayout.addView(yourView, layoutParams);

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多