我们需要完成如图的功能。
分4步:
首先先看布局
<View style="@style/separation_line"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/banner_bg">
<RelativeLayout
android:id="@+id/lay_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/common_selector_default"
android:paddingEnd="8dp"
android:paddingLeft="14dp"
android:paddingRight="8dp"
android:paddingStart="14dp">
<ImageView
android:id="@+id/iv_back"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_centerVertical="true"
android:background="@drawable/common_ic_back"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:background="@drawable/common_shape_search_view_bg"
android:gravity="center"
android:orientation="vertical">
<AutoCompleteTextView
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@null"
android:drawableLeft="@drawable/common_icon_search"
android:drawablePadding="5dp"
android:hint="搜索地点"
android:imeOptions="actionSearch"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/gray_66"
android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.amap.api.maps.MapView
android:id="@+id/mapView"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/app_loc"
android:translationY="-10dp" />
</FrameLayout>
<RelativeLayout
android:background="@color/gray_dd"
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/ensure"
android:layout_toLeftOf="@+id/ensure"
android:maxLines="1"
android:text=""
android:textColor="#333333"
android:textSize="13dp"
android:visibility="gone"/>
<TextView
android:id="@+id/addressDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/ensure"
android:layout_centerVertical="true"
android:maxLines="1"
android:textColor="#999999"
android:textSize="12dp" />
<Button
android:id="@+id/btn_ensure"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:background="@drawable/common_selector_green_button"
android:text="确定"
android:textColor="#ffffff"
android:textSize="13dp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_poi"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
首先进来是定位自己的位置。
这里封装了一下地图的定位
ALocationClientFactory类
public class ALocationClientFactory {
public static final String DEFAULT_TAG = "Default";
public static AMapLocationClientOption createDefaultOption() {
AMapLocationClientOption option =