android仿qq微信的消息数量显示功能
2016-06-17 10:24
501 查看
下面是显示数量布局的代码。其实很简单,就是帧布局嵌套帧布局就好了。 <LinearLayout android:id="@+id/ft_fragment_home_accept_layout" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:orientation="vertical" android:paddingBottom="15dp" > <FrameLayout android:layout_width="48dp" android:layout_height="58dp" android:layout_marginTop="10dp"> <ImageView android:layout_width="50dp" android:layout_height="50dp" android:scaleType="center" android:src="@mipmap/home_dd" android:layout_gravity="center" /> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right"> <ImageView android:id="@+id/ft_fragment_home_accept_number_img" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="center" android:src="@mipmap/round_1" android:visibility="gone"/> <TextView android:id="@+id/ft_fragment_home_accept_number" style="@style/base_text_white_12" android:textSize="10sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:layout_gravity="center" /> </FrameLayout> </FrameLayout> <TextView style="@style/base_text_grey_light_15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="17dp" android:text="@string/receive2" /> </LinearLayout> 下面是实现逻辑,很简单,就是动态的去控制数量的显示,以及数量是个位数和两位数,三位数不同的背景显示。
void getTotal(final boolean showLoad) { Map<String, Object> argMap = HttpUtil.getEncryMap(getActivity()); if (SharedUtil.getCustomcode(getActivity()) != null) { argMap.put("customcode", SharedUtil.getCustomcode(getActivity())); } ShowLoadTask task = new ShowLoadTask(getActivity(), taskTag, containLayout, loadLayout, "", showLoad, iOnTryClickListener, BaseConstant.getHomepageStatistics, argMap, TaskConstant.POST); task.setParseClass(HomeNumberResult.class); task.setiOnResultListener(new IOnResultListener() { @Override public void onOK(DispatchTask task) { if (task.resultEntity instanceof HomeNumberResult) { HomeNumberResult res = (HomeNumberResult) task.resultEntity; numDataEntity = res.data; if (numDataEntity == null) { acceptNumber.setText(""+0); workorderNumber.setText(""+0); acceptNumberImg.setVisibility(View.GONE); acceptNumber.setVisibility(View.GONE); workorderNumberImg.setVisibility(View.GONE); workorderNumber.setVisibility(View.GONE); } else { orderNumber = numDataEntity.waitReceiveCount; worknumber = numDataEntity.repairOrderCount + numDataEntity.helpOrderCount; acceptNumber.setText("" + numDataEntity.waitReceiveCount); workorderNumber.setText("" + (worknumber)); acceptNumberImg.setVisibility(View.VISIBLE); acceptNumber.setVisibility(View.VISIBLE); workorderNumberImg.setVisibility(View.VISIBLE); workorderNumber.setVisibility(View.VISIBLE); if (numDataEntity.waitReceiveCount ==0){ acceptNumberImg.setVisibility(View.GONE); acceptNumber.setVisibility(View.GONE); }else { acceptNumberImg.setVisibility(View.VISIBLE); acceptNumber.setVisibility(View.VISIBLE); } if (worknumber ==0){ workorderNumberImg.setVisibility(View.GONE); workorderNumber.setVisibility(View.GONE); }else { workorderNumberImg.setVisibility(View.VISIBLE); workorderNumber.setVisibility(View.VISIBLE); } if (numDataEntity.waitReceiveCount < 10) { acceptNumberImg.setImageDrawable(getResources().getDrawable(R.mipmap.round_1)); } else if (numDataEntity.waitReceiveCount > 10&&numDataEntity.waitReceiveCount<100) { acceptNumberImg.setImageDrawable(getResources().getDrawable(R.mipmap.round_2)); } else if (numDataEntity.waitReceiveCount > 100) { acceptNumberImg.setImageDrawable(getResources().getDrawable(R.mipmap.round_3)); } if (worknumber < 10) { workorderNumberImg.setImageDrawable(getResources().getDrawable(R.mipmap.round_1)); } else if (worknumber > 10&&worknumber<100) { workorderNumberImg.setImageDrawable(getResources().getDrawable(R.mipmap.round_2)); } else if (worknumber > 100) { workorderNumberImg.setImageDrawable(getResources().getDrawable(R.mipmap.round_3)); } } } } @Override public void onError(DispatchTask task) { LogUtil.e("请求失败"); } @Override public void onDone(DispatchTask task) { try { } catch (Exception e) { e.printStackTrace(); } } } ); task.execute(); }当然如果在其他页面有其他操作导致数量改变,发送个广播,在接收广播里做下逻辑处理就好了
相关文章推荐
- 社交巨头三国杀:微信、WhatsApp、Line到底有啥区别?
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件