Android快速SDK(10)地址库Location【傻瓜模式】

来源:互联网 发布:idc联想数据 编辑:程序博客网 时间:2024/06/06 01:59

代码:http://download.csdn.net/detail/huangbin95487710/9258865

依赖包模式

完整运行还需要用到以下依赖包
  • Android快速SDK(2)View库QuickView
  • Android快速SDK(3)数据库Sqlite

  1. 属性配置,一般使用默认配置即可
    • 支持更改背景颜色
    • 支持更改字体大小,左右间距,可见速度
    • 支持更改每行的高度与间距
    • 支持城市,省份,区域组合显示
    • <declare-styleable name="LocationView">        <!-- 精确度 -->        <attr name="location_accuracy">            <enum name="province" value="0" />            <enum name="city" value="1" />            <enum name="district" value="2" />        </attr>        <!-- item文字颜色 -->        <attr name="location_value_text_color" format="color" />        <!-- item选中文字颜色 -->        <attr name="location_items_text_color" format="color" />        <!-- 背景颜色 -->        <attr name="location_background_color" format="color" />        <!-- 字体大小 -->        <attr name="location_text_size" format="dimension" />        <!-- 左右间距 -->        <attr name="location_padding" format="dimension" />        <!-- 可见数量 -->        <attr name="location_visible_items" format="integer" />        <!-- 滚动速度 -->        <attr name="location_scrolling_duration" format="integer" />        <!-- item高度 -->        <attr name="location_additional_item_height" format="dimension" />        <!-- item间距 -->        <attr name="location_additional_items_space" format="dimension" />        <attr name="android:layout_width" />        <attr name="android:layout_height" />    </declare-styleable>

    • 默认样式
    • <style name="DivLocationView">        <item name="location_accuracy">district</item>        <item name="location_value_text_color">@color/location_def_value_text_color</item>        <item name="location_items_text_color">@color/location_def_items_text_color</item>        <item name="location_background_color">@color/location_def_background_color</item>        <item name="location_text_size">@dimen/location_def_text_size</item>        <item name="location_padding">@dimen/location_def_padding</item>        <item name="location_visible_items">@integer/location_def_visible_items</item>        <item name="location_scrolling_duration">@integer/location_def_scrolling_duration</item> </style>
  2. 代码示例
    • 布局XML
    •     <RelativeLayout        android:id="@+id/picker_layout"        android:layout_width="match_parent"        android:layout_height="fill_parent"        android:layout_alignParentBottom="true" >        <General.Location.LoactionView.LocationView            android:id="@+id/location"            style="@style/MyDivLocationView"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_marginLeft="10dp"            android:layout_marginRight="10dp"            android:layout_marginTop="25dp" />    </RelativeLayout>

    • 代码
    • package cn.whonow.whonow.loc;import General.Location.DB.LocService;import General.Location.LoactionView.LocationDto;import General.Location.LoactionView.LocationView;import General.Location.LoactionView.onLocationChangeListener;import General.System.MyLog;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import cn.whonow.whonow.R;/** 必须实现onLocationChangeListener接口 */public class LocActivity extends Activity implements onLocationChangeListener {private LocService mLocService;private LocationView mLocation;private LocationDto mDto;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.test_loc);mLocService = new LocService(this);mLocation = (LocationView) findViewById(R.id.location);mLocation.setOnLoactionChangeListener(this);mLocation.setVisibility(View.INVISIBLE);Button mButtonTxt = (Button) findViewById(R.id.button1);mButtonTxt.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// 获取默认列表信息MyLog.show(LocActivity.this, "省份列表:"+ mLocService.getDefaultProvince().size() + " 默认城市列表:"+ mLocService.getDefaultCity().size() + " 默认区县列表:"+ mLocService.getDefaultDistrict().size());}});Button mButton2 = (Button) findViewById(R.id.button2);mButton2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// 显示选择列表mLocation.setVisibility(View.VISIBLE);}});Button mButton3 = (Button) findViewById(R.id.button3);mButton3.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// 隐藏选择列表mLocation.setVisibility(View.INVISIBLE);MyLog.show(LocActivity.this, "省份:" + mDto.provinceName + " 城市:"+ mDto.cityName + " 区县:" + mDto.districtName);}});}@Overridepublic void onLocationChange(LocationDto base) {// TODO Auto-generated method stubmDto = base;}}

  3. 效果图
0 0
原创粉丝点击