上一节对“我”模块(一)进行了综述(可参见 “我”模块(一) 进行了解),接下来将从“我”模块(二)开始详细介绍:

知识点

掌握“日历”界面的开发,使用日历展示当前年份

掌握“星座”界面的开发,选择不同的星座展示不同的运势

掌握“涂鸦”界面的开发,实现图画的绘制功能

掌握“地图”界面的开发,可以定位一个指定地点

星座

任务综述:

点击“星座”界面右上角的“切换”按钮会弹出“星座选择”界面,该界面主要用于展示十二星座的图标、名称、阳历日期,点击“星座选择”界面上的任意一个星座,会显示对应星座的详细信息。

7. “星座选择”界面

任务分析:

“星座选择”界面主要用于展示十二星座的相关信息,界面效果如图所示。

“星座选择”界面

任务实施:

(1)创建“星座选择”界面:ChooseConstellationActivity & activity_choose_constellation。

(2)导入界面图片(choose_constella_close_icon)。

(3)放置界面控件。

一个ImageView控件用于显示关闭按钮;

一个TextView控件用于显示“选择星座”文字;

一个View控件用于显示灰色分割线;

一个RecyclerView控件用于显示十二星座的列表信息。

activity_choose_constellation.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/transparent"

android:orientation="vertical">

android:id="@+id/iv_close"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:src="@drawable/choose_constella_close_icon" />

android:layout_width="240dp"

android:layout_height="match_parent"

android:background="@android:color/white"

android:orientation="vertical">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:padding="8dp"

android:text="选择星座"

android:textColor="@color/choose_constellation_title_color"

android:textSize="14sp" />

android:layout_width="match_parent"

android:layout_height="1dp"

android:layout_marginLeft="15dp"

android:layout_marginRight="15dp"

android:background="@color/divider_line_color" />

android:id="@+id/rv_list"

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:divider="@null"

android:dividerHeight="0dp"

android:fadingEdge="none"

android:paddingBottom="8dp"

android:paddingTop="8dp" />

(4)修改colors.xml,添加一个名为choose_constellation_title_color的颜色值用于设置选择星座文本的颜色。

#8bdcea

8. “星座选择”界面Item

任务分析:

“星座选择”界面是使用RecyclerView控件展示十二星座列表的,因此需要创建一个该列表的Item界面。在Item界面中需要展示星座图标、名称以及阳历日期,界面如图所示。

“星座选择”界面Item

任务实施:

(1)创建“星座选择”界面Item:choose_constella_item.xml。

(2)放置界面控件。

一个ImageView控件用于显示星座图片;

两个TextView控件分别用于显示星座名称与星座阳历日期。

choose_constella_item.xml

android:layout_width="240dp"

android:layout_height="25dp"

android:layout_marginLeft="30dp"

android:background="@android:color/white"

android:gravity="center_vertical">

android:id="@+id/iv_constella_img"

android:layout_width="20dp"

android:layout_height="20dp"

android:scaleType="fitXY" />

android:id="@+id/tv_contella_name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="6dp"

android:textColor="@android:color/black"

android:textSize="13sp" />

android:id="@+id/tv_date"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="6dp"

android:textColor="@android:color/black"

android:textSize="13sp" />

9. “星座选择”界面Adapter

任务分析:

“星座选择”列表界面是使用RecyclerView控件战士星座信息,因此需要创建一个数据适配器ChooseConstellationListAdapter对RecyelerView控件进行数据适配。

任务实施:

(1)创建ChooseConstellationListAdapter类。在adapter包中创建一个ChooseConstellaListAdapter类继承RecyclerView.Adapter类,并重写onCreateViewHolder()、onBindViewHolder()、getItemCount()方法。

(2)创建ViewHolder类。在ChooseConstellaListAdapter类中创建一个ViewHolder类用于获取Item界面上的控件。

ChooseConstellationListAdapter.java

public class ChooseConstellaListAdapter extends RecyclerView.Adapter implements View.OnClickListener {

private List cbList;

private Context context;

private OnItemClickListener mOnItemClickListener = null;

public ChooseConstellaListAdapter(Context context) {

this.context = context;

}

public void setOnItemClickListener(OnItemClickListener listener) {

this.mOnItemClickListener = listener;

}

public void setData(List cbList) {

this.cbList = cbList;

notifyDataSetChanged();

}

@Override

public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)

{

View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.

choose_constella_item, viewGroup, false);

ViewHolder viewHolder = new ViewHolder(view);

view.setOnClickListener(this);

return viewHolder;

}

@Override

public void onBindViewHolder(final RecyclerView.ViewHolder holder, int i) {

ConstellationBean bean = cbList.get(i);

((ViewHolder) holder).tv_contella_name.setText(bean.getName());

((ViewHolder) holder).tv_date.setText(bean.getDate());

Glide

.with(context)

.load(bean.getImg())

.error(R.mipmap.ic_launcher)

.into(((ViewHolder) holder).iv_img);

//将i保存在itemView的Tag中,以便点击时进行获取

holder.itemView.setTag(i);

}

@Override

public int getItemCount() {

return cbList == null ? 0 : cbList.size();

}

@Override

public void onClick(View v) {

if (mOnItemClickListener != null) {

//注意这里使用getTag方法获取position

mOnItemClickListener.onItemClick(v, (int) v.getTag());

}

}

public class ViewHolder extends RecyclerView.ViewHolder {

public TextView tv_contella_name, tv_date;

public ImageView iv_img;

public ViewHolder(View itemView) {

super(itemView);

tv_contella_name = (TextView) itemView.findViewById(R.id.tv_contella_name);

tv_date = (TextView) itemView.findViewById(R.id.tv_date);

iv_img = (ImageView) itemView.findViewById(R.id.iv_constella_img);

}

}

public interface OnItemClickListener {

void onItemClick(View view, int position);

}

}

10.“星座选择”界面数据

任务分析:

“星座选择”界面的图片存放在Tomcat的ROOT文件夹中的constellation文件夹中数据是通过在ROOT文件夹中创建一个choose_constellation_list_data.json文件存放的。

任务实施:

(1)存放“星座选择”界面的图片。将“星座选择”界面需要的图片放入Tomcat的ROOT/newsdemo/topline/img/constellation文件夹中。

(2)创建“星座选择”界面数据文件。在Tomcat的ROOT/nesdemo目录中创建一个choose_constellation_list_data.json文件,该文件用于存放“星座选择”界面需要加载的数据。

choose_constellation_list_data.json

[

{

"id":1,

"name":"白羊座",

"img":"http://172.25.32.1:8080/newsdemo/img/constellation/baiyang_icon.png",

"date":"(阳历3.21-4.19)",

},

……

{

"id":12,

"name":"双鱼座",

"img":"http://172.25.32.1:8080/newsdemo/img/constellation/shuangyu_icon.png",

"date":"(阳历2.19-3.20)",

}

]

(3)修改Constant.java文件。在utils包中的Constant类中添加一个名为REQUEST_CHOOSE_CONSTELLATION_LIST_URL的“星座选择”界面接口地址。

//星座选择界面接口

public static final String REQUEST_CHOOSE_CONSTELLATION_LIST_URL = "/choose_constellation_list_data.json";

11.“星座选择”界面逻辑代码

任务分析:

“星座选择”界面主要显示星座的图标、名称以及阳历日期。点击每个星座会关闭界面并显示“星座选择”界面,同时会把选择的星座Id回传给“星座”界面。

任务实施:

(1)获取界面控件。在ChooseConstellationActivity中创建界面控件的初始化方法init(),获取“星座选择”界面所要用到的控件。

(2)获取数据。在ConstellationActivity中创建getData()方法,用于获取服务器中的十二星座信息数据。

ChooseConstellationActivity.java

public class ChooseConstellationActivity extends AppCompatActivity {

private ImageView iv_close;

private ChooseConstellaListAdapter adapter;

private OkHttpClient okHttpClient;

public static final int MSG_CHOOSE_CONSTELLATION_OK = 1;//获取星座数据

private MHandler mHandler;

private RecyclerView recyclerView;

private List list;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_choose_constellation);

mHandler = new MHandler();

okHttpClient = new OkHttpClient();

getData();

init();

}

private void init() {

iv_close = (ImageView) findViewById(R.id.iv_close);

recyclerView = (RecyclerView) findViewById(R.id.rv_list);

//这里用线性显示 类似于 ListView

recyclerView.setLayoutManager(new LinearLayoutManager(this));

adapter = new ChooseConstellaListAdapter(ChooseConstellationActivity.this);

recyclerView.setAdapter(adapter);

iv_close.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ChooseConstellationActivity.this.finish();

}

});

adapter.setOnItemClickListener(new ChooseConstellaListAdapter.

OnItemClickListener() {

@Override

public void onItemClick(View view, int position) {

Intent intent = new Intent();

intent.putExtra("id", list.get(position).getId());

setResult(RESULT_OK, intent);

ChooseConstellationActivity.this.finish();

}

});

}

/**

* 事件捕获

*/

class MHandler extends Handler {

@Override

public void dispatchMessage(Message msg) {

super.dispatchMessage(msg);

switch (msg.what) {

case MSG_CHOOSE_CONSTELLATION_OK:

if (msg.obj != null) {

String result = (String) msg.obj;

list = JsonParse.getInstance().getConstellaList(result);

if (list != null) {

if (list.size() > 0) {

adapter.setData(list);

}

}

}

break;

}

}

}

private void getData() {

Request request = new Request.Builder().url(Constant.WEB_SITE +

Constant.REQUEST_CHOOSE_CONSTELLATION_LIST_URL).build();

Call call = okHttpClient.newCall(request);

//开启异步线程访问网络

call.enqueue(new Callback() {

@Override

public void onResponse(Response response) throws IOException {

String res = response.body().string();

Message msg = new Message();

msg.what = MSG_CHOOSE_CONSTELLATION_OK;

msg.obj = res;

mHandler.sendMessage(msg);

}

@Override

public void onFailure(Request arg0, IOException arg1) {

}

});

}

}

(3)修改清单文件。由于“星座选择”界面是对话框的样式,在清单文件的ChooseConstellationActivity对应的activity标签中添加如下代码:

android:name=".activity.ChooseConstellationActivity"

android:theme="@style/AppTheme.NoTitle.Dialog" />

(4)修改“星座”界面逻辑代码。由于点击“星座”界面右上角的“切换”按钮会跳转到“星座选择”界面,因此需要在ConstellationActivity的init()方法,在该方法找找到tv_switch控件的点击事件,并在该控件的点击事件中添加如下代码:

Intent intent = new Intent(ConstellationActivity.this,ChooseConstellationActivity.class);

startActivityForResult(intent, 1);

android 日期控件计算星座,21. “我”模块(二)之星座选择相关推荐

  1. Android日期控件

    (请先认真读一下前两段,谢谢) 最近做了一个电商的Android原生项目,其中有一个酒店预订的功能,要实现一个日期控件,基本就是入住时间,离店时间,日期控件需要连续展示一年或者几年的按月份显示的连续视 ...

  2. Android日期控件如何兼容不同手机

    ============问题描述============ 请看图 但是,在小米或者华为手机上,日期控件却显示 2014-09月-03 ,月份一栏中多了一个"月"字,这种感觉很不爽: ...

  3. Android学习|控件——Notification通知

    Android学习|控件--Notification通知 一.前提 二.两个对象的的构建 1.创建NotificationManager 2.使用Builder构造器来创建Notification 2 ...

  4. Android学习--02(猜猜我的星座App源码+Android常用控件TextView+EditText+Button+ImangeView+DatePicker+App间通信+跳转页面)

    猜猜我的星座App 1 Android常用控件 1.1 TextView控件 1.1.1 简介 1.1.2属性 1.1.3 扩展属性 1.1.4 TextView的使用方法 1.1.5总结 1.2 E ...

  5. 【Android从零单排系列十一】《Android视图控件——日历、日期、时间选择控件》

    目录 一.日历.日期.时间组件基本介绍 二.几种常见的控件类型 1.CalendarView –日历控件 2. DatePicker –日期选择控件 3.TimePicker –时间选择控件 4.Ch ...

  6. Android图表控件MPAndroidChart——BarChart实现多列柱状图以及堆积柱状图

    目录 前言 1. 数据准备 1.1 数据来源 2. 图表展示 2.1 MPAndroidChart获取 2.2 数据对象获取 2.3 数据展示 3. 柱状图外观完善 3.1 去掉图表外框,描述内容以及 ...

  7. 一个Demo让你掌握Android所有控件

    一个Demo让你掌握Android所有控件 原文:一个Demo让你掌握Android所有控件 本文是转载收藏,侵删,出处:"安卓巴士"      下面给出实现各个组件的源代码: 1 ...

  8. android时间控件

    原文地址:http://www.360doc.com/content/14/0617/16/18203124_387517665.shtml 前言 这一篇博客分别讲解Android平台下,关于日期和时 ...

  9. Android图表控件MPAndroidChart——LineChart实现 XY轴、原点线的直尺刻度样式

    接上文: Android图表控件MPAndroidChart--曲线图LineChart的使用(多条曲线) 其他相关文章: Android图表控件MPAndroidChart的简单介绍(MPAndro ...

  10. Android 原生控件之一 TextView

    Android 原生控件之一 TextView 前言 来源 开始 XML属性 1.android:allowUndo 2.android:autoLink 3.android:autoSizeMaxT ...

最新文章

  1. 十年后,这是25个你会习以为常的AI应用场景
  2. Spring+MyBatis
  3. 随机森林 python_如何轻松使用python的随机森林
  4. UML、XML、WebService,NUnit单元测试,测试驱动开发,httphandl,httpmodel
  5. Android为spinner设置适配器,Android Spinner与适配器模式详解及实例代码
  6. JAVA WEB 对返回数据进行按中文名称首字母A~Z升序排序
  7. iframe加载完成后操作contentDocument
  8. [原创]手动配置Ubuntu Linux系列3-缺省网关和主机名
  9. VS 反编译工具 ildasm
  10. 银行计算机综合知识,银行秋招综合知识测试包含哪些专业课?
  11. 使用 JsDelivr作为CDN 加速服务
  12. Hbuilder 真机运行显示未受信任的解决方法(ios)
  13. 实现Windows下Qt扫描U盘的两种方式
  14. 前端table导出excel表格方法汇总
  15. (PDC2008)Anders Hejlsberg: The Future of C#
  16. iit delhi_IIT的完整形式是什么?
  17. SAP甲方历程回顾-01 2017年转到甲方的故事~从乙方离职
  18. 新网站多久被google收录?谷歌当天收录网站靠谱吗?
  19. 京东API提取方法-获得JD商品详情API
  20. mac远程桌面Microsoft Remote Desktop for Mac - Mac-连接Windows远程桌面

热门文章

  1. 核心期刊为什么难发?
  2. 计算机网络工程师 一共几级,2020年计算机软考网络工程师中级多少分过
  3. BeatSaber节奏光剑双手柄MR教程
  4. Windows Server 2012 R2 服务器密码忘记问题
  5. 2021年信息系统监理师考试大纲
  6. 2021-04-27
  7. 80386常用内部寄存器
  8. Biztalk AS2开发经验总结
  9. 语音识别(html5+nodejs)
  10. opencv双目测距