您的位置:首页 > 移动开发 > 微信开发

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();
}
当然如果在其他页面有其他操作导致数量改变,发送个广播,在接收广播里做下逻辑处理就好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 布局 qq 微信