Arcgis for Android Collout的簡單使用

來源:互聯網
上載者:User

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();//得到MapView的Callout,一個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 效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.