全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Android带数字或红点的底部导航拦和联网等待加载动画示例

Android带数字或红点的底部导航拦和联网等待加载动画

首先展示一下截图效果,下载地址在文章最后

一、Android带红点的底部导航拦

1.首先写底部导航栏的界面view_main_tab.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="#27282c"
>

<RelativeLayout
android:id="@+id/rl_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">

<RadioButton
android:id="@+id/rb_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:button="@null"
android:background="@null"
android:checked="true"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_home"
android:gravity="center"
android:text="首页"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />

<TextView
android:id="@+id/tv_1"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_1"
android:layout_alignTop="@id/rb_1"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>

</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:focusable="true">

<RadioButton
android:id="@+id/rb_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_goods_divide"
android:gravity="center"
android:text="商品"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />

<TextView
android:id="@+id/tv_2"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_2"
android:layout_alignTop="@id/rb_2"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">

<RadioButton
android:id="@+id/rb_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_stock_list"
android:gravity="center"
android:text="进货单"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />

<TextView
android:id="@+id/tv_3"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_3"
android:layout_alignTop="@id/rb_3"
android:layout_marginTop="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>

</RelativeLayout>


<RelativeLayout
android:id="@+id/rl_4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:layout_weight="1">

<RadioButton
android:id="@+id/rb_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:button="@null"
android:clickable="false"
android:drawablePadding="5dp"
android:drawableTop="@drawable/selector_tab_member"
android:gravity="center"
android:text="会员"
android:textColor="@drawable/tab_text_selector"
android:textSize="10sp" />


<TextView
android:id="@+id/tv_4"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignRight="@id/rb_4"
android:layout_alignTop="@id/rb_4"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:layout_gravity="right"
android:background="@drawable/msg_num_shape"
android:clickable="false"
android:gravity="center"
android:text="3"
android:textColor="@color/white_1"
android:textSize="10sp"
/>
</RelativeLayout>

</LinearLayout>

2.修改底部导航栏的数字,在MainActivity中

 /**
 * -1:表示没有新消息
 * -2:表示新消息用红点的方式显示
 * 0-99:直接显示数字
 * >=100:用99+显示
 */
private void messageTips(int num, TextView tv) {
if(num==-1){
 tv.setVisibility(View.GONE);
}else if(num==-2){
tv.setVisibility(View.VISIBLE);
tv.setText("");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,10);
layoutParams.width= DensityUtil.dip2px(this,10);
tv.setLayoutParams(layoutParams);
}else if(num>=0&&num<=99){
tv.setVisibility(View.VISIBLE);
tv.setText(num+"");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,16);
layoutParams.width= DensityUtil.dip2px(this,16);
tv.setLayoutParams(layoutParams);
}else if(num>=100){
tv.setVisibility(View.VISIBLE);
tv.setText("99+");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,16);
layoutParams.width= DensityUtil.dip2px(this,16);
tv.setTextSize(DensityUtil.sp2px(this,3));
tv.setLayoutParams(layoutParams);
}else{
tv.setVisibility(View.GONE);
}

}

3.需要在fragment中修改MainActivity中的底部导航拦,所以,要在MainActivity中,写一些公用的方法。

 /**
 * 在oneFragment中更新,底部导航栏的数字
 * @param num
 */
public void updateOne(int num){
messageTips(num,tv_1);
}
/**
 * 在TwoFragment中更新,底部导航栏的数字
 * @param num
 */
public void updateTwo(int num){
messageTips(num,tv_2);
}
/**
 * 在ThreeFragment中更新,底部导航栏的数字
 * @param num
 */
public void updateThree(int num){
messageTips(num,tv_3);
}
/**
 * 在FourFragment中更新,底部导航栏的数字
 * @param num
 */
public void updateFour(int num){
messageTips(num,tv_4);
}

4.在fragment中修改底部导航拦,得到主页面,调用主页面的修改方法。

mActivity = (MainActivity) getActivity();
number++;
mActivity.updateTwo(number);

二、activity加载动画。

1.activity中的加载动画,要写一个BaseActivity。布局如下

<?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/activity_base"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.hrobbie.loadingproject.activity.BaseActivity">


<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentInsetStart="0.0dp"
android:background="@color/colorPrimary"
app:layout_scrollFlags="enterAlways|scroll"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
<FrameLayout
android:id="@+id/fl_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/loading_anim"/>
</FrameLayout>

</LinearLayout>

注意:id为fl_content的FrameLayout的布局里,包含了一个loading_anim的布局,这就是加载布局。加载布局,里面氛围三个线性布局,分别是:加载中布局,加载错误布局,没有数据布局,其中加载失败布局,还需要点击重新加载。内容如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!--加载中-->
<LinearLayout android:id="@+id/ll_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="90dp"
android:gravity="center"
android:orientation="vertical"
>

<ImageView
android:id="@+id/iv_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/loading_everyday" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="正在为您开启干货推荐.."
android:textColor="@color/colorTitle"
android:textSize="14sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:text="看的越多,推荐越准"
android:textColor="@color/colorSubtitle"
android:textSize="12sp"
android:visibility="visible" />

</LinearLayout>


<!--加载失败-->
<LinearLayout
android:id="@+id/ll_error_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">

<ImageView
android:id="@+id/img_err"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/load_err" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="加载失败,点击重试"
android:textSize="15sp" />
</LinearLayout>
<!--加载失败-->
<LinearLayout
android:id="@+id/ll_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">

<ImageView
android:id="@+id/img_no_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/load_err" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="sorry,没有您想要的数据"
android:textSize="15sp" />
</LinearLayout>
</FrameLayout>

2.Baseactivity的代码太多,讲一下主要的,重写setContentView方法,把新布局放入id为fl_content的布局中,调用getWindow()。setContentView(rootView);剩下的就跟普通个activity操作一样了。

@Override
public void setContentView(@LayoutRes int layoutResID) {
 View rootView = LayoutInflater.from(this).inflate(R.layout.activity_base,null,false);
addView = LayoutInflater.from(this).inflate(layoutResID, null, false);


//content
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addView.setLayoutParams(params);
fl_content = (FrameLayout) rootView.findViewById(R.id.fl_content);
fl_content.addView(addView);
getWindow().setContentView(rootView);

initView();
showLoading();
}

3.新的activity只需集成BaseActivity,当需要加载成功是,调用loadSuccess()方放,加载失败时调用loadError(),失败后重新加载,需要调用reLoading()重新加载,并调用onRefresh()重新加载数据。如果没有数据调用noData()

三、fragment中加载动画,把加载布局,放入fragment中我暂时没有好的办法提出BaseFragment进行统一加载。有一些注意事项。

1.viewpager进行布局加载时,最好能够预加载一个屏幕的数据。

 vp_main.setOffscreenPageLimit(3);//最好是一屏能显示的fragment数-1。

2.在BaseFragment重写setUserVisibleHint方法,当fragment可见时,才联网加载数据。

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);

if (getUserVisibleHint()){
isVisible=true;
onVisible();
}else {
isVisible=false;
onInvisible();
}
}

3.fragment继承BaseFragment需要在onViewCreated中调用一下联网加载方法,因为,setUserVisibleHint执行比较靠前,页面还没有添加到布局,就加载数据,会造成填充数据失败,需要当页面完全添加到布局中,再联网请求。

 @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mActivity= (MainActivity) getActivity();
showLoading();
lazyLoad();
}

下载地址:LoadingProject_jb51.rar

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# android  # 小红点提示  # 消息提醒红点  # 加载等待动画  # android实现加载动画对话框  # Android 自定义加载动画Dialog弹窗效果的示例代码  # android自定义波浪加载动画的实现代码  # Android 使用 Path 实现搜索动态加载动画效果  # Android自定义带加载动画效果的环状进度条  # Android自定义view利用Xfermode实现动态文字加载动画  # Android Glide图片加载(加载监听、加载动画)  # Android仿支付宝笑脸刷新加载动画的实现代码  # Android实现跳动的小球加载动画效果  # Android实现仿微软系统加载动画效果  # 加载  # 下载地址  # 重写  # 新消息  # 还没有  # 加载中  # 太多  # 这就是  # 为您  # 只需  # 要在  # 如果没有  # 还需要  # 越多  # 暂时没有  # 首页  # 就跟  # 您想  # 大家多多  # 要写 


相关文章: 如何用景安虚拟主机手机版绑定域名建站?  如何高效完成独享虚拟主机建站?  已有域名如何快速搭建专属网站?  建站主机是否属于云主机类型?  c# 在高并发场景下,委托和接口调用的性能对比  C++如何将C风格字符串(char*)转换为std::string?(代码示例)  建站之星免费模板:自助建站系统与智能响应式一键生成  如何在景安云服务器上绑定域名并配置虚拟主机?  网站制作公司排行榜,抖音怎样做个人官方网站  如何制作网站标识牌,动态网站如何制作(教程)?  如何在阿里云高效完成企业建站全流程?  云南网站制作公司有哪些,云南最好的招聘网站是哪个?  盘锦网站制作公司,盘锦大洼有多少5G网站?  网站制作的软件有哪些,制作微信公众号除了秀米还有哪些比较好用的平台?  南京做网站制作公司,南京哈发网络有限公司,公司怎么样,做网页美工DIV+CSS待遇怎么样?  制作充值网站的软件,做人力招聘为什么要自己交端口钱?  西安制作网站公司有哪些,西安货运司机用的最多的app或者网站是什么?  如何在香港服务器上快速搭建免备案网站?  教学网站制作软件,学习*后期制作的网站有哪些?  制作网站的基本流程,设计网站的软件是什么?  宁波自助建站系统如何快速打造专业企业网站?  网站视频怎么制作,哪个网站可以免费收看好莱坞经典大片?  建站VPS推荐:2025年高性能服务器配置指南  网站制作模板下载什么软件,ppt模板免费下载网站?  临沂网站制作公司有哪些,临沂第四中学官网?  如何基于PHP生成高效IDC网络公司建站源码?  制作网站的软件免费下载,免费制作app哪个平台好?  制作农业网站的软件,比较好的农业网站推荐一下?  深圳网站制作公司好吗,在深圳找工作哪个网站最好啊?  建站之星代理费用多少?最新价格详情介绍  交易网站制作流程,我想开通一个网站,注册一个交易网址,需要那些手续?  建站之星后台密码遗忘如何找回?  百度网页制作网站有哪些,谁能告诉我百度网站是怎么联系?  太原网站制作公司有哪些,网约车营运证查询官网?  如何在万网自助建站中设置域名及备案?  网站制作员失业,怎样查看自己网站的注册者?  洛阳网站制作公司有哪些,洛阳的招聘网站都有哪些?  完全自定义免费建站平台:主题模板在线生成一站式服务  网站按钮制作软件,如何实现网页中按钮的自动点击?  如何在西部数码注册域名并快速搭建网站?  湖州网站制作公司有哪些,浙江中蓝新能源公司官网?  如何快速选择适合个人网站的云服务器配置?  C#怎么创建控制台应用 C# Console App项目创建方法  广德云建站网站建设方案与建站流程优化指南  实惠建站价格推荐:2025年高性价比自助建站套餐解析  建站主机选购指南:核心配置优化与品牌推荐方案  建站之星如何优化SEO以实现高效排名?  css网站制作参考文献有哪些,易聊怎么注册?  早安海报制作网站推荐大全,企业早安海报怎么每天更换?  已有域名如何免费搭建网站? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。