android 地址控件概述
最近,公司做项目,需要一个地址控件,本来是想androidcopy开源的android的地址控件,但是了,找来找去。都没有找到一个真正满足我的需求的,普通的地址控件只是精确到市县区三级,但是我们的需求是精确到乡镇四级。于是,做了一个。
我设计思路就是模仿jquery的并列的地址的选择控件,当选择上一级着,直接来跳转到下一级进行选择。设计的原型图为这样:
看到这样布局的方式很显然用gridview数据表格的方式来显示省市县的数据。而每个的数据网格的布局的方式只需要一个textview来显示相应的数据的方式就可以了。这两个的布局文件的样子如下所示:
gridview的布局文件的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <GridView
android:id="@+id/gridview_county"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/back_color"
android:gravity="center"
android:horizontalSpacing="1dp"
android:numColumns="5" android:columnWidth="80dp"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp" />
</LinearLayout>
每项item的布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <GridView
android:id="@+id/gridview_county"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/back_color"
android:gravity="center"
android:horizontalSpacing="1dp"
android:numColumns="5" android:columnWidth="80dp"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp" />
</LinearLayout>
这两个文件都十分的简洁,真是有了这个布局文件作为基础,才能实现这个控件的真正的布局来实现了,那么他的真正的组装的布局的文件又是那个样子了。这就用了一个slideview来把这四个布局文件来包裹起来了。同时来实现相应的动画效果。他的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" > <LinearLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="#FFFFFFFF"
android:orientation="horizontal" > <FrameLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/a"
android:clickable="true" > <TextView
android:id="@+id/table_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:tag="0"
android:text="省份"
android:textColor="@color/text_down"
android:textSize="16dp" />
</FrameLayout> <FrameLayout
android:id="@+id/frame_route_baseinfo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/b"
android:clickable="false"
android:focusable="false" > <TextView
android:id="@+id/table_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:tag="1"
android:text="地市"
android:textColor="@color/text_normal"
android:textSize="16dp" />
</FrameLayout> <FrameLayout
android:id="@+id/frame_countyinfo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/b"
android:clickable="false"
android:focusable="false"
android:textColor="@color/text_normal" > <TextView
android:id="@+id/table_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:tag="2"
android:text="区县"
android:textColor="@color/text_normal"
android:textSize="16dp" />
</FrameLayout> <FrameLayout
android:id="@+id/frame_countryinfo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/b"
android:clickable="true" > <TextView
android:id="@+id/table_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:tag="3"
android:text="乡镇/街道"
android:textColor="@color/text_normal"
android:textSize="16dp" />
</FrameLayout>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/c"
android:orientation="vertical" >
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <com.example.address_ctrl.element.SlideChangeView
android:id="@+id/slide_change_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <LinearLayout
android:id="@+id/provinceview_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" > <include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/provinceview" />
</LinearLayout> <LinearLayout
android:id="@+id/cityview_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <include
android:layout_width="match_parent"
android:layout_height="fill_parent"
layout="@layout/cityview" />
</LinearLayout> <LinearLayout
android:id="@+id/countyview_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <include
android:layout_width="match_parent"
android:layout_height="fill_parent"
layout="@layout/countyview" />
</LinearLayout> <LinearLayout
android:id="@+id/countryview_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <include
android:layout_width="match_parent"
android:layout_height="fill_parent"
layout="@layout/countryview" />
</LinearLayout>
</com.example.address_ctrl.element.SlideChangeView>
</LinearLayout>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingBottom="20dp" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" > <TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="选择地址"
android:textColor="@color/normal_color" /> <EditText
android:id="@+id/address_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:background="@color/text_normal"
android:editable="false"
android:textColor="@color/black_color" /> <Button
android:id="@+id/car_no_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="确定" />
</LinearLayout>
</LinearLayout> </LinearLayout>
通过上面的源代码,我们可以明确的看到,有个editext来接受你选择的相应的结果,有个button来确定你选择的结果,这样子的话,就构成 一个完整的地址的空间的布局了。
值得一提的,这里有一个所谓的SlideChangeView自定义的控件,这实现的功能本身和viewflipper差不多了,这不过这里能够继承了自定义的动画,似的翻页的时候来更生动形象。至于这里的控制文件无非是加载数据在进行了相应的逻辑判断,我就不再这里进行太多赘述。
最终控件的效果如下:

android 地址控件概述的更多相关文章
- android 时间控件概述
android的自带时间选择控件,是一个让用户既能输入的又能选择的样子.这本来没有太大的问题了. 但是,坑爹的android是开源的.自带的时间控件在某些机型上,早已经是面目全非了,在用以一个普通用户 ...
- Android圆环控件
Android圆环控件 近期在做一个功能.界面效果要求例如以下: 看到这个界面,我首先想到了曾经在做phone模块的时候,我们定制的来电界面InCallTouchUi,界面效果是相似的. 来电控件使用 ...
- Android 开源控件与常用开发框架开发工具类
Android的加载动画AVLoadingIndicatorView 项目地址: https://github.com/81813780/AVLoadingIndicatorView 首先,在 bui ...
- 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl
[源码下载] 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl 作者:webabcd 介绍与众不同 windows p ...
- android 基础控件(EditView、SeekBar等)的属性及使用方法
android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...
- Android基本控件之Menus
在我们的手机中有很多样式的菜单,比如:我们的短信界面,每条短信,我们长按都会出现一个菜单,还有很多的种类.那么现在,我们就来详细的讨论一下安卓中的菜单 Android的控件中就有这么一个,叫做Menu ...
- Android:控件布局(相对布局)RelativeLayout
RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列. 相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above-- ...
- Android:控件布局(线性布局)LinearLayout
LinearLayout是线性布局控件:要么横向排布,要么竖向排布 决定性属性:必须有的! android:orientation:vertical (垂直方向) .horizontal(水平方向) ...
- 矩阵, 矩阵 , Android基础控件之ImageView
天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...
随机推荐
- JAVAEE——Lucene基础:什么是全文检索、Lucene实现全文检索的流程、配置开发环境、索引库创建与管理
1. 学习计划 第一天:Lucene的基础知识 1.案例分析:什么是全文检索,如何实现全文检索 2.Lucene实现全文检索的流程 a) 创建索引 b) 查询索引 3.配置开发环境 4.创建索引库 5 ...
- nova event
nova处理neutron发送过来的event事件.暂时追踪nova event部分代码 tail -f /var/log/nova/nova-api.log 下面就是一个事件 Creating ...
- [ 转载 ] Java基础4--Java中的static关键字解析
Java中的static关键字解析 static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面就先讲述一下static关键 ...
- WinForm 数据库无限填充树目录 treeView
我自己想的是处理数据库每一条数据,然后来插入子节点的子节点. 奈何没有插入子节点的子节点的办法,百度来百度去,一看全都是递归. 本来我是绝望的, 但是没办法,老板的需求不能驳回啊,于是就来ctrl c ...
- Centos7(Firewall)防火墙开启常见端口命令
使用云服务器的,一定要注意开启安全组配置的响应端口 Centos7默认安装了firewalld,如果没有安装的话,则需要YUM命令安装:firewalld真的用不习惯,与之前的iptable防火墙区别 ...
- BZOJ2055 80人环游世界 网络流 费用流 有源汇有上下界的费用流
https://darkbzoj.cf/problem/2055 https://blog.csdn.net/Clove_unique/article/details/54864211 ←对有上下界费 ...
- 【单调队列】BZOJ1342-[Baltic2007]Sound静音问题
[题目大意] 给出一个n个数的序列,以哪位位置为开头的长度为m的区间满足该区间的最大值与最小值的差≤一个定值. [思路] 单调队列……说一下单调队列比较方便的操作. 把第一个先丢进去,开始条件为hea ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- javascript中Date对象复习
js的Date对象不怎么经常用,所以忘得差不多,复习一下 1.声明一个Date对象,默认本地当前时间 var date = new Date();//Fri Apr 28 2017 14:26:19 ...
- 重温PHP面向对象的三大特性
PHP面向对象的三大特性:封装性.继承性.多态性. 1. 封装性: 也称为信息隐藏,就是将一个类的使用和实现分开,只保留部分接口和方法与外部联系,或者说只公开了一些供开发人员使用的方法. 于是开发人员 ...