您现在的位置是:首页 > 文章详情

仿抖音底部导航(二)

日期:2018-05-08点击:395

继续实现仿抖音底部导航

今天要实现效果如下图

img_daa440e9339305fb35247a7c5022e8cc.gif
实现效果

首先在原基础的布局中加入一个ImageView

<LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:id="@+id/nav_top" android:layout_centerInParent="true" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:text="标题" android:id="@+id/nav_item_tv_title" android:textColor="#F1F1F1" android:textSize="16sp" android:layout_height="wrap_content" /> <!--新加入的--> <ImageView android:id="@+id/reflash" android:layout_width="25dp" android:src="@mipmap/shuaxin" android:visibility="gone" android:layout_centerInParent="true" android:layout_height="25dp" /> </LinearLayout> 

这里附上刷新的图片素材

img_9cd0a3334f9c7f596523e99c58e07b12.png
image

然后在原代码中进行修改以实现导航的动画及刷新功能

1.添加是否显示刷新图片的标记

//默认设为flase private boolean isShowReflashImage=false; //并添加set方法 public void setShowReflashImage(boolean showReflashImage) { isShowReflashImage = showReflashImage; } 

2.然后修改激活和取消激活的方法

public void startActive(){ //根据上一步添加的标记来判断是否显示ImageView if(isShowReflashImage){ textView_title.setVisibility(GONE); imageView_Shuaxin.setVisibility(VISIBLE); }else { textView_title.setTextColor(Color.WHITE); textView_title.setTextSize(18); } textView_line.animate().alpha(1).setDuration(200).start(); } public void cancelActive(){ if(isShowReflashImage){ textView_title.setVisibility(VISIBLE); imageView_Shuaxin.setVisibility(GONE); textView_line.setAlpha(0); }else { textView_title.setTextColor(Color.parseColor("#F1F1F1")); textView_title.setTextSize(16); } textView_line.animate().alpha(0).setDuration(200).start(); } 

3.给负责刷新的ImageView添加旋转动画

private void initListener() { final Animation rotateAnimation = new RotateAnimation(0,-360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); rotateAnimation.setDuration(300); imageView_Shuaxin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { imageView_Shuaxin.startAnimation(rotateAnimation); } }); } 

4.最后加上刷新事件

1)新建NavItemReflashListener
public interface NavItemReflashListener { void onReflash(View v); } 
2)给NavItemView加上NavItemReflashListener属性并设置set方法
public void setNavItemReflashListener(NavItemReflashListener navItemReflashListener) { this.navItemReflashListener = navItemReflashListener; } 
3)在imageView_Shuaxin的点击事件中调用onReflash(View v)方法
imageView_Shuaxin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { imageView_Shuaxin.startAnimation(rotateAnimation); if(navItemReflashListener!=null){ navItemReflashListener.onReflash(v); } } }); 

5.在MainActivity中将想要显示刷新控件的NavItemView设置ShowReflashImagewei为true并加上刷新事件

navItemView1.setShowReflashImage(true); navItemView1.setNavItemReflashListener(new NavItemReflashListener() { @Override public void onReflash(View v) { Toast.makeText(MainActivity.this, "刷新", Toast.LENGTH_SHORT).show(); } }); 

最后附上完整代码https://gitee.com/itfittnesss/DouYin

原文链接:https://yq.aliyun.com/articles/665593
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章