Arcgis For Android 不支持中文解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013758734/article/details/41702025

之前项目用的Arcgis for Android版本为10.2.1,TextSymbol还支持中文,现在升级到了10.2.4竟然不支持中文了,所有的中文都被空格替换掉了,郁闷了半天,现在找到了一个比较好的解决方案,绕过TextSymbol。

之前做IOS的同事也遇到过这种情况,不过他将PictureMarkerSymbol和TextSymbol添加到CompositeSymbol中,然后再将CompositeSymbol加入到Graphic中,解决了该问题,但是我这次试这种方案,发现不能用了。

现在说一下我的解决思路吧,我使用的是PictureMarkerSymbol,看一下他的一个构造方法:

public PictureMarkerSymbol (Drawable drawable)

参数是一个Drawable对象,如果我们把所有的要在弹出气泡中显示的信息放在一个View中,然后把View转为Drawable对象,问题不就解决了吗?
下面看一下效果图最后的效果图吧:


在这里我贴出两段比较关键的代码:
1.加载View视图
	private View getGraphicView(Point point)
	{
		RelativeLayout view=(RelativeLayout)getLayoutInflater().inflate(R.layout.pop_graphic_view,null);
		DisplayMetrics metrics=getResources().getDisplayMetrics();
		int density=(int)metrics.density;
		//之所以在这儿设置LayoutParams参数,是因为在如果不这样设置,在之后调用view.measure时在某些Android版本上会报空指针异常
		//在4.1.2回报空指针,4.4.2不会报,具体是设备原因还是Android版本原因没有详细测试,条件有限
		RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,80*density);
		layoutParams.setMargins(0, 0, 0, 0);
		view.setLayoutParams(layoutParams);
		//这里要说明一点,textView的singleLine属性值不能设置为true,
		//否则textView上所有的文字会叠加在一起,成为一个密密麻麻的点
		//不信你可以试试
		TextView textView=(TextView) view.findViewById(R.id.tv_content);
		textView.setText("您点击的坐标详细信息:\nX:"+point.getX()+"\nY:"+point.getY());
		return view;
	}
pop_graphic_view布局文件内容为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/pop_bg"
    android:padding="0dp"
    android:layout_width="160dp"
    android:layout_height="60dp" >
    <TextView 
        android:id="@+id/tv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:textColor="#fff"
        android:textSize="16sp"
        android:padding="5dp"
        android:layout_marginBottom="10dp"
        />
</RelativeLayout>

2.View转为Bitmap:
	/**
	 * 将View转换为BitMap
	 * @param view
	 * @return
	 */
	public static Bitmap convertViewToBitmap(View view){
		view.destroyDrawingCache();
		view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
				View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
		view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
		view.setDrawingCacheEnabled(true);
		return view.getDrawingCache(true);
	}
然后生成Drawable对象:
Drawable drawable=new BitmapDrawable(null, bitmap);
生成PictureMarkerSymbol对象:
PictureMarkerSymbol symbol=new PictureMarkerSymbol(drawable);
以上即为核心代码片段,代码都比较简单,不多做解释了,主要是解决问题的思路。
源码下载地址:

猜你喜欢

转载自blog.csdn.net/u013758734/article/details/41702025