Arcgis for Android Collout的简单使用

本文详细阐述了如何在Android应用中定义Callout的外观,并通过XML文件指定样式,同时利用布局文件来填充显示内容。通过点击屏幕触发Callout的显示,实现交互式的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1      定义callout的外观,可以在一个xml中定义

   <?xml version="1.0" encoding="utf-8"?>
  <resources>
      <calloutViewStyle
         titleTextColor="#000000" <!—标题颜色/>
         titleTextSize = 10; <!—标题字体大小/>
         titleTextStyle = 0; <!—标题字体/>
          backgroundColor="#ffffff" <!—背景颜色/>
          backgroundAlpha="255" <!—透明度 0(透明) to 255(不透明) />
          frameColor="#000000" <!—边框颜色/>
          flat="true" <!—是否会在3D效果/>
         cornerCurve="0"   <!—圆角的度数/>
          anchor="5" /> <!—锚的位置(0-8/> 
   </resources>

2      定义callout要显示的内容,可以在一个layout中定义。

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:gravity="center">

    <ImageView

       android:src="@drawable/ic_launcher"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       />

    <TextViewandroid:text="这个是callout"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"/>

</LinearLayout>

 

3      显示callout,以下代码实现单击屏幕的时候,把callout显示出来

public class CalloutTestActivity extends Activityimplements OnSingleTapListener {

MapViewmMapView ;

private Calloutcallout;

 

    /** Called when the activity is first created. */

    @Override

    public void onCreate(BundlesavedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

 

    mMapView =(MapView)findViewById(R.id.mapView);

    ArcGISTiledMapServiceLayerarm=new ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");

    mMapView.addLayer(arm);

    mMapView.setOnSingleTapListener(this);

    callout=mMapView.getCallout();//得到MapViewCallout,一个MapView只能有一个Callout

    }

 

public void onSingleTap(float arg0,float arg1) {

    Pointp=mMapView.toMapPoint(new Point(arg0, arg1)); 

callout.setStyle(R.xml.colloutxml);//设置显示样式(第1步定义的xml

callout.setContent(View.inflate(this, R.layout.colloutlay,null));//把第2步的定义的layout作为callout的显示内容

    callout.setCoordinates(p); //设置显示的位置为单击的位置

    callout.show();//显示callout

}

}


4 效果


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值