Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android之百度地圖 前期實現

Android之百度地圖 前期實現

編輯:關於Android編程

Android之百度地圖前期實現
//以下是寫的幾個類

package com.android.mapelves.org;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.ZoomControls;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.ItemizedOverlay;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.MapActivity;
import com.baidu.mapapi.MapController;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.MyLocationOverlay;
import com.baidu.mapapi.OverlayItem;
@SuppressLint({ "ParserError", "ParserError" })
public class MainActivity extends MapActivity {
 private int lat;
 private int lon;
 //加載百度地圖相關控件
 private MapView mapView;
 //加載地圖引擎
 private BMapManager bMapManager;
 //百度地圖key
 private String mapKey="64C2995A762A8C16C9A9DA8928B0F42489D5C106";
    //在百度地圖上添加一些控件,放大與縮小
 private MapController mapController;
 // 地圖覆蓋物
    private MyLocationOverlay mLocationOverlay;
    //地圖模式切換
   private ToggleButton modelChange;
   //設置是否開啟實時路況
   private ToggleButton roadCond;
   //搜索
   private ImageView search;
   //線路
   private ImageView road;
   //附近
   private ImageView nearby;
   //導航
   private ImageView navBar;
 @SuppressLint("ParserError")
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        mapView = (MapView)this.findViewById(R.id.bmapView);
        modelChange = (ToggleButton)findViewById(R.id.model_change);
        roadCond = (ToggleButton)findViewById(R.id.road_cond);
        bMapManager = new BMapManager(MainActivity.this);
       
        Bundle bundle = new Bundle();
        bundle = this.getIntent().getExtras();
        lat = bundle.getInt("lat");
        lon = bundle.getInt("lon");
       
        //加載key
        bMapManager.init(mapKey, new MKGeneralListener() {
  
   public void onGetPermissionState(int arg0) {
    // TODO Auto-generated method stub
    if (arg0 == 300) {
     Toast.makeText(MainActivity.this, "驗證失敗", Toast.LENGTH_LONG).show();
    }
   }
  
   public void onGetNetworkState(int arg0) {
    // TODO Auto-generated method stub
   
   }
  });
       
        this.initMapActivity(bMapManager);
        mapView.setBuiltInZoomControls(true);//可以設置縮放功能
        mapView.setDrawOverlayWhenZooming(true);
        mapController = mapView.getController();
        //獲取mapview中的縮放控件 
        ZoomControls zoomControls = (ZoomControls) mapView.getChildAt(2);
        //調整縮放控件的位置 
        zoomControls.setPadding(0, 0, 0, 100);
        mLocationOverlay = new MyLocationOverlay(this, mapView);
        mLocationOverlay.enableCompass();
        // 添加定位覆蓋物
        mapView.getOverlays().add(mLocationOverlay);
        //事先定義各異經緯度
        mapController.setZoom(15);//縮放級別
        Drawable drawable = getResources().getDrawable(R.drawable.iconmarka);
        mapView.getOverlays().add(new MyOverlayItem(drawable));
        mapView.setTraffic(true);//顯示交通地圖
        mapView.invalidate();
        modelChange.setOnCheckedChangeListener(new ModelChangeListener());
        roadCond.setOnCheckedChangeListener(new RoadCondListener());
       
        nearby = (ImageView)findViewById(R.id.nearby);
        nearby.setOnClickListener(null);
       
        search = (ImageView)findViewById(R.id.search);
        search.setOnClickListener(new Searchlistener());
       
        road = (ImageView)findViewById(R.id.road);
        road.setOnClickListener(new Roadlistener());
       
        navBar = (ImageView)findViewById(R.id.nav);
        nearby.setOnClickListener(null);
       
 }
 //是否開啟實時路況
 class RoadCondListener implements OnCheckedChangeListener{

  public void onCheckedChanged(CompoundButton buttonView,
    boolean isChecked) {
   // TODO Auto-generated method stub
   if (isChecked) {
    mapView.setTraffic(true);
    mapView.invalidate();
    Toast.makeText(MainActivity.this, "實時路況已開啟", Toast.LENGTH_LONG).show();
   }else {
    mapView.setTraffic(false);
    mapView.invalidate();
    Toast.makeText(MainActivity.this, "實時路況已關閉", Toast.LENGTH_LONG).show();
   }
  }
 
 }
 //線路
 class Roadlistener implements OnClickListener{

  public void onClick(View v) {
   // TODO Auto-generated method stub
   RelativeLayout rl = (RelativeLayout) findViewById(R.id.RelativeLayout_roadsearch_top);
   if(rl.getVisibility() == View.GONE){
    rl.setVisibility(View.VISIBLE);
   }else{
    rl.setVisibility(View.GONE);
   }
  }
 
 }
 //搜索
 class Searchlistener implements OnClickListener{

  public void onClick(View v) {
   Intent intent = new Intent();
   intent.setClass(MainActivity.this, SearchActivity.class);
   startActivity(intent);
  }
 
 }
 
 public class MyOverlayItem extends ItemizedOverlay<OverlayItem>{
 
  private List<OverlayItem> list = new ArrayList<OverlayItem>();
 
  //用於地圖標識坐標,用一個圖片標注
  public MyOverlayItem(Drawable drawable){
   super(drawable);
   GeoPoint geoPoint = new GeoPoint(lat, lon);
   mapController.setCenter(geoPoint);//設置中心點
   list.add(new OverlayItem(geoPoint, "我在這兒", "我在這兒"));
   populate();
  }
 
  //返回指定的list結合的每一個坐標
  @Override
  protected OverlayItem createItem(int arg0) {
   // TODO Auto-generated method stub
   return list.get(arg0);
  }
 
  @Override
  public int size() {
   // TODO Auto-generated method stub
   return list.size();
  }
 
  @Override
  public boolean onTap(int i) {
   // TODO Auto-generated method stub
   Toast.makeText(MainActivity.this, list.get(i).getSnippet(), Toast.LENGTH_LONG).show();
   return true;
  }
 }
 
 @Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  if (bMapManager != null) {
   bMapManager.destroy();
   bMapManager = null;
  }
 }
 
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  if (bMapManager != null) {
   bMapManager.start();
  }
 }
 
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  if (bMapManager != null){
   bMapManager.stop();
  }
 }
 
 public class ModelChangeListener implements OnCheckedChangeListener{
  public void onCheckedChanged(CompoundButton buttonView,
    boolean isChecked) {
   if (isChecked){
    mapView.setTraffic(false);
    mapView.setSatellite(true);
    mapView.invalidate();
   }
   else {
    mapView.setSatellite(false);
    mapView.setTraffic(true);
    mapView.invalidate();
   }
  }
 }
 
 @Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;
 }
   
}

 

//鑒於沒時間就沒實現了

package com.android.mapelves.org;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class SearchActivity extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.search);
 }
 
}


 

package com.android.mapelves.org.getlotion;

import android.R.integer;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Window;
import android.widget.Toast;

import com.android.mapelves.org.MainActivity;
import com.android.mapelves.org.R;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.LocationListener;
import com.baidu.mapapi.MKAddrInfo;
import com.baidu.mapapi.MKBusLineResult;
import com.baidu.mapapi.MKDrivingRouteResult;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.MKLocationManager;
import com.baidu.mapapi.MKPoiResult;
import com.baidu.mapapi.MKSearch;
import com.baidu.mapapi.MKSearchListener;
import com.baidu.mapapi.MKSuggestionResult;
import com.baidu.mapapi.MKTransitRouteResult;
import com.baidu.mapapi.MKWalkingRouteResult;
import com.baidu.mapapi.MapActivity;

public class GetLocationActivity extends MapActivity{
 private int lat;
 private int lon;
 private BroadcastReceiver receiver;
 private String ACTION = "LOCATION_CHANGE_ACTION";
 //百度地圖key
 private String mapKey="64C2995A762A8C16C9A9DA8928B0F42489D5C106";
 private BMapManager bMapManager;
 private MKSearch mkSearch;
 private ProgressDialog dialog;
 @Override
 protected void onCreate(Bundle arg0) {
  // TODO Auto-generated method stub
  super.onCreate(arg0);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.face);
  bMapManager = new BMapManager(this);
  bMapManager.init(mapKey, new MKGeneralListener() {
  
   public void onGetPermissionState(int arg0) {
    // TODO Auto-generated method stub
    if (arg0 == 300) {
     Toast.makeText(GetLocationActivity.this, "驗證失敗", Toast.LENGTH_LONG).show();
     dialog.dismiss();
    }
   }
  
   public void onGetNetworkState(int arg0) {
    // TODO Auto-generated method stub
    Toast.makeText(GetLocationActivity.this, "網絡出錯", Toast.LENGTH_LONG).show();
    dialog.dismiss();
   }
  });
 
  this.bMapManager.start();
  mkSearch = new MKSearch();
  dialog = ProgressDialog.show(this, "定位", "正在定位,請稍候...", true, true);
  new MyThread(this).start();
 }
 
 private class MyThread extends Thread{
  private GetLocationActivity activity;
 
  public MyThread(GetLocationActivity activity) {
   // TODO Auto-generated constructor stub
   this.activity = activity;
  }
 
  @Override
  public void run() {
   // TODO Auto-generated method stub
   super.run();
   //Looper.prepare();
   onceStartMyLocation();
   mkSearch.init(bMapManager, new MyMKSearchlistener());
  
   receiver = new BroadcastReceiver() {
   
    @Override
    public void onReceive(Context context, Intent intent) {
     // TODO Auto-generated method stub
     intent.getAction();
     Bundle bundle = intent.getExtras();
     if (bundle.getInt("lat") != 0 && bundle.getInt("lon") != 0) {
      lat = bundle.getInt("lat");
      lon = bundle.getInt("lon");
      handler.sendEmptyMessage(0);
     }
    }
   };
   IntentFilter iFilter = new IntentFilter();
   iFilter.setPriority(Integer.MAX_VALUE);
   iFilter.addAction(ACTION);
   registerReceiver(receiver, iFilter);
  }
 }
 
 private Handler handler = new Handler() { 
        @Override 
        public void handleMessage(Message msg) { 
         if (dialog.isShowing()){ 
          dialog.dismiss();
          Intent intent = new Intent(GetLocationActivity.this, MainActivity.class);
         
          //intent.setClass(GetLocationActivity.this, MainActivity.class);
          intent.putExtra("lon", lon);
          intent.putExtra("lat", lat);
          startActivityForResult(intent, 11);
          int version = Integer.valueOf(android.os.Build.VERSION.SDK);
          if(version  >= 5) {    
               overridePendingTransition(R.anim.anim_in, R.anim.anim_out);  //此為自定義的動畫效果,下面兩個為系統的動畫效果
               //overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);  
               //overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
          } 
          unregisterReceiver(receiver);
          //startActivity(intent);
          GetLocationActivity.this.finish();
         }
        } 
 }; 
 
 private class MyMKSearchlistener implements MKSearchListener{

  public void onGetAddrResult(MKAddrInfo arg0, int arg1) {
   // TODO Auto-generated method stub
   if (arg0 == null) { 
                return; 
            } 
   Intent intent = new Intent();
   intent.setAction(ACTION);
   intent.putExtra("lon", arg0.geoPt.getLongitudeE6());
   intent.putExtra("lat", arg0.geoPt.getLatitudeE6());
   sendBroadcast(intent);
  }

  public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }

  public void onGetDrivingRouteResult(MKDrivingRouteResult arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }

  public void onGetPoiDetailSearchResult(int arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }

  public void onGetPoiResult(MKPoiResult arg0, int arg1, int arg2) {
   // TODO Auto-generated method stub
  
  }

  public void onGetRGCShareUrlResult(String arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }

  public void onGetSuggestionResult(MKSuggestionResult arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }

  public void onGetTransitRouteResult(MKTransitRouteResult arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }

  public void onGetWalkingRouteResult(MKWalkingRouteResult arg0, int arg1) {
   // TODO Auto-generated method stub
  
  }
 
 }
 // 一直定位自己的位置
 private LocationListener locationListener = new LocationListener() {
 
  public void onLocationChanged(Location location) {
   if (location != null) {
    Double geolat = location.getLatitude() * 1E6;
    Double geoLng = location.getLongitude() * 1E6;
    GeoPoint mypoint = new GeoPoint(geolat.intValue(), geoLng.intValue());
          
    mkSearch.reverseGeocode(mypoint);         
   }
  }
 };
 
 private void onceStartMyLocation() {
  bMapManager.getLocationManager().enableProvider(MKLocationManager.MK_NETWORK_PROVIDER);
  bMapManager.getLocationManager().requestLocationUpdates(locationListener);
  bMapManager.getLocationManager().setNotifyInternal(0, 0);  //設置通知間隔,單位秒
 }
 
 @Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;
 }
 
 @Override
 protected void onResume() {
  bMapManager.start();
  super.onResume();
 }

 @Override
 protected void onPause() {
  bMapManager.getLocationManager().removeUpdates(locationListener);
  bMapManager.stop();
  super.onPause();
 }
 
 @Override
 public void onBackPressed() {
  // TODO Auto-generated method stub
  super.onBackPressed();
  dialog.dismiss();
 }
}


 

 

以下是anim文件下的內容

anim_in.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/decelerate_interpolator"> 
    <scale android:fromXScale="2.0" android:toXScale="1.0" 
           android:fromYScale="2.0" android:toYScale="1.0" 
           android:pivotX="50%p" android:pivotY="50%p" 
           android:duration="@android:integer/config_mediumAnimTime" /> 
</set>

 

anim_out.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/decelerate_interpolator" 
        android:zAdjustment="top"> 
    <scale android:fromXScale="1.0" android:toXScale=".5" 
           android:fromYScale="1.0" android:toYScale=".5" 
           android:pivotX="50%p" android:pivotY="50%p" 
           android:duration="@android:integer/config_mediumAnimTime" /> 
    <alpha android:fromAlpha="1.0" android:toAlpha="0" 
           android:duration="@android:integer/config_mediumAnimTime"/> 
</set>

 

 以下是drawable文件的內容

btn_default_small.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_enabled="false" android:drawable="@drawable/btn_default_small_normal_disable" />
    <item android:state_pressed="true" android:drawable="@drawable/btn_default_small_pressed" />
    <item android:drawable="@drawable/btn_default_small_normal" />
</selector>

 

btn_its_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/btn_its_open" />
    <item android:drawable="@drawable/btn_its_close" />
</selector>


btn_map_poi.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/direct_mapsearch_pressed" />
    <item android:drawable="@drawable/direct_mapsearch" />
</selector>

 

btn_nav_drag_down.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/btn_nav_drag_down_pressed" />
    <item android:drawable="@drawable/btn_nav_drag_down_normal" />
</selector>

 

mode_driving.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/mode_driving_focused" />
    <item android:drawable="@drawable/mode_driving_off" />
</selector>

 

mode_transit.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/mode_transit_focused" />
    <item android:drawable="@drawable/mode_transit_on" />
</selector>

 

mode_walk.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/mode_walk_focused" />
    <item android:drawable="@drawable/mode_walk_off" />
</selector>

 

shape.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/> 
    <corners android:radius="8px"/> 
    <stroke 
        android:width="2px" 
        /> 
</shape>

 

text_search.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="false" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/text_search_default" />
    <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/text_search_pressed" />
    <item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/text_search_selected" />
</selector>

 

以下是幾個布局文件

face.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:orientation="vertical" >
    <ImageView
        android:src="@drawable/bg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>

 

main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <com.baidu.mapapi.MapView
        android:id="@+id/bmapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ToggleButton
         android:id="@+id/model_change"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:alpha="0.7"
         android:textOn="衛星地圖"
         android:textOff="交通地圖"/>
     <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:layout_below="@id/model_change"
         android:paddingRight="4.0dip" >

         <ToggleButton
             android:id="@+id/road_cond"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:background="@drawable/btn_its_selector"
             android:checked="false"
             android:textOff=""
             android:textOn="" />
            </LinearLayout>
         <TableLayout
             android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="#D3D3D3"
                android:alpha="0.8"
             >
             <TableRow >
                 <FrameLayout
                     android:layout_weight="1"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content">
                     <LinearLayout
                         android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:orientation="vertical">
                         <ImageView
                             android:id="@+id/nearby"
                             android:src="@drawable/nearby"
                             android:layout_gravity="center"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"/>
                            <TextView
                             android:text="附近"
                             android:layout_width="wrap_content"
                             android:layout_gravity="center"
                             android:layout_height="wrap_content"
                             android:textStyle="italic"/>
                     </LinearLayout>
                    </FrameLayout>
                    <FrameLayout
                        android:layout_weight="1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                     <LinearLayout
                         android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:orientation="vertical">
                         <ImageView
                             android:id="@+id/search"
                             android:src="@drawable/search"
                             android:layout_gravity="center"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"/>
                         <TextView
                             android:text="搜索"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_gravity="center"
                             android:textStyle="italic"
                             />
                     </LinearLayout>
                    </FrameLayout>
                    <FrameLayout
                        android:layout_weight="1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:orientation="vertical">
                            <ImageView
                             android:id="@+id/road"
                             android:src="@drawable/road"
                             android:layout_gravity="center"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"/>
                            <TextView
                             android:text="線路"
                             android:layout_gravity="center"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textStyle="italic"/>
                        </LinearLayout>
                    </FrameLayout>
                    <FrameLayout
                        android:layout_weight="1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:orientation="vertical">
                            <ImageView
                             android:id="@+id/nav"
                             android:src="@drawable/nav"
                             android:layout_gravity="center"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"/>
                         <TextView
                             android:text="導航"
                             android:layout_gravity="center"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:textStyle="italic"/>
                        </LinearLayout>
                    </FrameLayout>
                </TableRow>
         </TableLayout>
    </RelativeLayout>
    <RelativeLayout
        android:id="@id/RelativeLayout_roadsearch_top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/search_plate_global"
        android:visibility="gone"
        android:gravity="center" >

        <ImageButton
            android:id="@id/imagebtn_roadsearch_startoption"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="10.0dip"
            android:layout_marginTop="6.0dip"
            android:background="@android:color/transparent"
            android:src="@drawable/btn_nav_drag_down" />

        <ImageButton
            android:id="@id/imagebtn_roadsearch_goalsoption"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/imagebtn_roadsearch_startoption"
            android:layout_marginRight="10.0dip"
            android:layout_marginTop="8.0dip"
            android:background="@android:color/transparent"
            android:src="@drawable/btn_nav_drag_down" />

        <AutoCompleteTextView
            android:id="@id/autotextview_roadsearch_start"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/imagebtn_roadsearch_startoption"
            android:layout_marginLeft="5.0dip"
            android:layout_toLeftOf="@id/imagebtn_roadsearch_startoption"
            android:background="@drawable/text_search"
            android:dropDownVerticalOffset="1.0dip"
            android:hint="起點:"
            android:imeOptions="actionDone"
            android:inputType="text|textAutoComplete"
            android:maxLength="20"
            android:paddingRight="37.0dip"
            android:singleLine="true"
            android:textSize="16.0sp" />

        <AutoCompleteTextView
            android:id="@id/autotextview_roadsearch_goals"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignTop="@id/imagebtn_roadsearch_goalsoption"
            android:layout_marginLeft="5.0dip"
            android:layout_toLeftOf="@id/imagebtn_roadsearch_goalsoption"
            android:background="@drawable/text_search"
            android:dropDownVerticalOffset="1.0dip"
            android:hint="終點:"
            android:imeOptions="actionDone"
            android:inputType="text|textAutoComplete"
            android:maxLength="20"
            android:paddingRight="37.0dip"
            android:singleLine="true"
            android:textSize="16.0sp" />

        <LinearLayout
            android:id="@id/btn_layout"
            android:layout_width="fill_parent"
            android:layout_height="48.0dip"
            android:layout_below="@id/imagebtn_roadsearch_goalsoption"
            android:layout_marginLeft="10.0dip"
            android:layout_marginRight="6.0dip"
            android:layout_marginTop="6.0dip"
            android:orientation="horizontal"
            android:paddingBottom="10.0dip" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2.0"
                android:orientation="horizontal" >

                <Button
                    android:id="@id/imagebtn_roadsearch_tab_transit"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/mode_transit" />

                <Button
                    android:id="@id/imagebtn_roadsearch_tab_driving"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/mode_driving" />

                <Button
                    android:id="@id/imagebtn_roadsearch_tab_walk"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1.0"
                    android:background="@drawable/mode_walk" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10.0dip"
                android:layout_weight="3.0" >

                <ImageButton
                    android:id="@id/imagebtn_roadsearch_search"
                    android:layout_width="fill_parent"
                    android:layout_height="41.0dip"
                    android:background="@drawable/btn_default_small"
                    android:src="@drawable/btn_poi_search_normal" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
</FrameLayout>

 

search.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#D3D3D3"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableLayout
            android:background="#FFE4C4"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content">
         <TableRow>
             <EditText 
           android:id="@+id/et_search" 
           android:layout_width="fill_parent" 
           android:layout_weight="20"
           android:layout_height="wrap_content" 
           android:layout_gravity="center"  
           android:drawableLeft="@drawable/search" 
           android:background="@drawable/shape" 
           android:padding="10px" 
           android:hint="地點、公交、地鐵......" 
           android:singleLine="true" />
             <ImageButton
                 android:id="@+id/ht"
                 android:src="@drawable/ht"
                 android:background="@null"
                 android:layout_marginTop="10px"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"/>
         </TableRow>
     </TableLayout>
    </LinearLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:background="#FFA500"/>
    <TableLayout
        android:layout_marginTop="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow >
            <LinearLayout
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/repast"
                    android:src="@drawable/repast"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="餐飲"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
            <LinearLayout
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/shopping"
                    android:src="@drawable/shopping"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="購物"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </TableRow>
    </TableLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:background="#FFA500"/>
    <TableLayout
        android:layout_marginTop="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow >
            <LinearLayout
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/bank"
                    android:src="@drawable/bank"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="銀行"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/traffic"
                    android:src="@drawable/traffic"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="交通"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </TableRow>
    </TableLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:background="#FFA500"/>
    <TableLayout
        android:layout_marginTop="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow >
            <LinearLayout
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/stay"
                    android:src="@drawable/stay"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="住宿"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/life"
                    android:src="@drawable/life"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="生活"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </TableRow>
    </TableLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:background="#FFA500"/>
    <TableLayout
        android:layout_marginTop="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow >
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/entertainment"
                    android:src="@drawable/entertainment"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="娛樂休閒"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/pub"
                    android:src="@drawable/pub"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="公共設施"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </TableRow>
    </TableLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:background="#FFA500"/>
    <TableLayout
        android:layout_marginTop="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow >
            <LinearLayout
                android:layout_weight="1"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/car_service"
                    android:src="@drawable/car_service"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="汽車服務"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/government"
                    android:src="@drawable/government"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@null"/>
                <TextView
                    android:text="政府機關"
                    android:textSize="20dp"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </TableRow>
    </TableLayout>
</LinearLayout>

 

以下是values文件下的內容

ids.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <item type="id" name="RelativeLayout_roadsearch_top"></item>
   <item type="id" name="imagebtn_roadsearch_startoption"></item>
   <item type="id" name="imagebtn_roadsearch_goalsoption"></item>
   <item type="id" name="autotextview_roadsearch_start"></item>
   <item type="id" name="autotextview_roadsearch_goals"></item>
   <item type="id" name="btn_layout"></item>
   <item type="id" name="imagebtn_roadsearch_tab_transit"></item>
   <item type="id" name="imagebtn_roadsearch_tab_driving"></item>
   <item type="id" name="imagebtn_roadsearch_tab_walk"></item>
   <item type="id" name="imagebtn_roadsearch_search"></item>
</resources>

 

strings.xml

<resources>

    <string name="app_name">MapElves</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">地圖導航</string>
    <string name="toplayout_tv_search">查詢</string>
    <string name="search_title">搜索關鍵字</string>
</resources>

 

以下是配置文件

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.mapelves.org"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15"/>
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="false"
        android:smallScreens="true"
        android:resizeable="true"
        android:anyDensity="true" />
    <application
        android:hardwareAccelerated="false"
        android:icon="@drawable/iconmarka"
        android:label="地圖導航"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".getlotion.GetLocationActivity"
            android:label="地圖導航" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
       
        </activity>
        <activity android:name=".SearchActivity"></activity>
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
</manifest>

 

 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved