我正在使用谷歌地图API for Android。 地图在片段内。 我想在该片段中放置一个图像,并在地图上方。 我的目标是移动照片并使用Android手势调整事件大小。 我的问题是:如何在地图上放置图像?
我有一个方法可以返回一个包含图像的视图,然后让我移动并调整大小。
如何将此视图放入地图?
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/fotoPrueba"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
</fragment>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ImageTest);
View view = new SandboxView(this, bitmap); //returns me a View with the image and lets me move and resize.
ImageView iv= (ImageView)findViewById(R.id.fotoPrueba);
iv.setImageBitmap(bitmap);
//setContentView(view); // This works but deletes my map.
setContentView(R.layout.activity_main);
map= ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
答案 0 :(得分:0)
将您的视图放在地图片段之外的布局中。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/fotoPrueba"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"/>
<!-- here can be you view -->
<FrameLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>