[英]Google maps api custom marker
我正在從xml文件(RelativeLayout)尋找良好的功能或自定義標記的解決方案。
我有:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="55dp"
android:layout_height="65dp"
android:src="@drawable/custom_marker" />
<TextView
android:id="@+id/num_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="20"
android:textColor="#ce8223"
android:textSize="25dp"
android:textStyle="bold" />
</RelativeLayout>
如何使用它作為標記?
好吧,有一種解決方法可以將布局轉換為Drawable
並用作標記圖像:
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout)inflater.inflate(R.layout.your_layout, null);
view.setDrawingCacheEnabled(true);
view.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
//EDIT: updated drawable creation
Drawable d = new BitmapDrawable(context.getResources(), view.getDrawingCache().copy(Config.ARGB_8888, true)); //this drawable can be used as a marker
// **** EDIT2: don't forget to set bounds to your drawable
d.setBounds(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.setDrawingCacheEnabled(false);
如您所知,您需要存儲Context
指針以獲得LayoutInflater
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.