仿抖音底部導(dǎo)航(二)

繼續(xù)實(shí)現(xiàn)仿抖音底部導(dǎo)航

今天要實(shí)現(xiàn)效果如下圖

實(shí)現(xiàn)效果

首先在原基礎(chǔ)的布局中加入一個(gè)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="標(biāo)題"
        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>

這里附上刷新的圖片素材

image

然后在原代碼中進(jìn)行修改以實(shí)現(xiàn)導(dǎo)航的動(dòng)畫及刷新功能

1.添加是否顯示刷新圖片的標(biāo)記

//默認(rèn)設(shè)為flase
private boolean isShowReflashImage=false;
//并添加set方法
public void setShowReflashImage(boolean showReflashImage) {
    isShowReflashImage = showReflashImage;
}

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

public void startActive(){
    //根據(jù)上一步添加的標(biāo)記來(lái)判斷是否顯示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.給負(fù)責(zé)刷新的ImageView添加旋轉(zhuǎn)動(dòng)畫

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屬性并設(shè)置set方法
public void setNavItemReflashListener(NavItemReflashListener navItemReflashListener) {
    this.navItemReflashListener = navItemReflashListener;
}
3)在imageView_Shuaxin的點(diǎn)擊事件中調(diào)用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設(shè)置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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,889評(píng)論 25 709
  • 1.ios高性能編程 (1).內(nèi)層 最小的內(nèi)層平均值和峰值(2).耗電量 高效的算法和數(shù)據(jù)結(jié)構(gòu)(3).初始化時(shí)...
    歐辰_OSR閱讀 30,214評(píng)論 8 265
  • 不要因?yàn)榈謸醪蛔?夏天的紫外線 而去怪 太陽(yáng)傘的花邊 2014.09.03
    楊戲水閱讀 471評(píng)論 2 2
  • 寫完這個(gè)標(biāo)題,我愣了一下:昔日斯文的我怎么爆粗口了?發(fā)泄發(fā)泄吧…… 元月份,我懷孕了。孕早期反應(yīng)特別厲害,我多么希...
    千金女閱讀 467評(píng)論 5 2
  • 佛說(shuō) 眾生平等 ,但人的生活會(huì)分三六九等 。 一個(gè)人他尊重所有人 ,不是因?yàn)閯e人優(yōu)秀, 那是源于他自身的優(yōu)秀 。 ...
    讀牧人閱讀 308評(píng)論 0 1

友情鏈接更多精彩內(nèi)容