【ArcGIS for Android】使用自定义Callout显示地图信息

要想使用自定义的Callout,首先需要几个步骤:
1、定义Callout的样式
根据官方给的介绍,这里我们选择在res目录下新建一个xml目录,在目录里新建一个名为callout_style.xml的配置文件,用于配置callout的样式。代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <calloutViewStyle>
         titleTextColor="#000000"      <!-- 标题颜色 -->
         titleTextSize = 10;           <!-- 标题文字大小 -->
         titleTextStyle = 0;           <!-- 字体样式 -->
         titleTextTypeFace = 0;        <!-- 字体类型设置 --> 
         backgroundColor="#ffffff"    <!-- Callout背景颜色 -->
         backgroundAlpha="255"        <!-- Callout透明度 -->
         frameColor="#000000"         <!-- 边框颜色 -->
         flat="true"                  <!-- true表示2D图形,false表示3D图形 -->
         style.getCornerCurve()="0"   <!-- 边框的角的圆润程度 -->
         anchor="5"                   <!-- 锚点的位置--> 
    </calloutViewStyle>                
</resources>

2、自定义Callout的布局
我们在res/layout目录下新建一个callout_layout.xml的配置文件,用来布置Callout的界面布局。代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="12sp"/>
        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="12sp"/>

    </LinearLayout>

</LinearLayout>

3、在代码中使用Callout
定义好了配置文件,接下来就是在代码中使用这个Callout了,需要注意的是,一个MapView只能同时显示一个Callout,并且,这个Callout只能从MapView中获取。Java代码如下:

                    LayoutInflater inflater = LayoutInflater.from(context);  
                    View view = inflater.inflate(R.layout.callout_layout, null);
                    // 设置Callout属性
                    TextView title = (TextView)view.findViewById(R.id.title);
                    TextView content = (TextView)view.findViewById(R.id.content);
                    title.setText("这是Callout的标题");
                    content.setText("这是Callout的内容");
                    // 设置Callout锚点(MapView上的一个地图位置点)
                    Point test = new Point(map.toMapPoint(new Point(e.getX(),e.getY())).getX(),map.toMapPoint(new Point(e.getX(),e.getY())).getY()); 
                    // 获取Callout
                    Callout callout = map.getCallout();
                    // 设置Callout样式
                    callout.setStyle(R.xml.callout_style);
                    // 设置锚点偏移量
                    callout.setOffset(0, -5);
                    // 显示Callout
                    callout.show(test, view);
                    title.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {

                            Log.d(TAG, "你点了插图上的标题!但是并没什么动静。");

                        }
                    });
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值