仿Android印象笔记底部导航栏

最近用上了印象笔记,觉得android 版的底部导航栏挺不错的,好多应用里面都有用到,想着自己动手实现一下,不多说,先上图:

要完成这样的效果。需要自定义ViewGroup.

1、onMeasure(测量过程)

2、onLayout(布局)

3、添加动画

onMeasure(测量过程)

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int count = getChildCount();
        for (int i = 0; i<count;i++){
            View viewChild  = getChildAt(i);
            measureChild(viewChild,widthMeasureSpec,heightMeasureSpec);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

onLayout(布局)

 @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        View btn_main = getChildAt(getChildCount()-1);
        int left = 0;int top = 0;
        if (changed){
            for (int i = getChildCount()-1 ;i >= 0;i--){
                View viewChild  = getChildAt(i);
                int width = viewChild.getMeasuredWidth();
                int height = viewChild.getMeasuredHeight();
                left = getMeasuredWidth()- width;
                top = getMeasuredHeight() - height-distance;
                viewChild.layout(left,top,getMeasuredWidth(),getMeasuredHeight());
                distance += getDisension(100);
            }
            btn_main.setOnClickListener(this);
            changeState(currentState);
        }
    }

添加动画

public void openTranslateAnimation(View view){
        distance = 0;
        RotateAnimation animation = new RotateAnimation(0f,45f, Animation.RELATIVE_TO_SELF,
                0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        animation.setDuration(500);
        animation.setFillAfter(true);
        view.startAnimation(animation);
        for (int i = getChildCount()-2;i>= 0; i--){
            View childView = getChildAt(i);
            view.setVisibility(View.VISIBLE);
            TranslateAnimation translate = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
                    Animation.RELATIVE_TO_SELF, 0.35f, Animation.RELATIVE_TO_SELF, 0);
            translate.setDuration(100);
            translate.setStartOffset(10*offset);
            translate.setFillAfter(true);
            childView.startAnimation(translate);
            offset++;
        }
    }

    public void closeTranslateAnimation(View view){
        distance = 0;
        RotateAnimation animation = new RotateAnimation(45f,0, Animation.RELATIVE_TO_SELF,
                0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        animation.setDuration(500);
        animation.setFillAfter(true);
        view.startAnimation(animation);
        for (int i = getChildCount()-2;i>= 0; i--){
            View childView = getChildAt(i);
            view.setVisibility(View.VISIBLE);
            TranslateAnimation translate = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
                    Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.35f);
            translate.setDuration(100);
            translate.setStartOffset(50*offset);
            childView.startAnimation(translate);
            offset++;
        }
    }

看一下主布局:

<com.xby.fm.view.StackMenu
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="10dp"
                android:text="首页"
                />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_menu_item"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="10dp"
                android:text="我的音乐"
                />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_menu_item"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="10dp"
                android:text="我的收藏"
                />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_menu_item"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="10dp"
                android:text="个人中心"
                />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_menu_item"
                />
        </LinearLayout>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_main_menu"
                />
    </com.xby.fm.view.StackMenu>

比较简单,上一下git地址:StackMenu

时间: 2024-07-29 21:51:04

仿Android印象笔记底部导航栏的相关文章

Android 修改底部导航栏navigationbar的颜色

Android 修改底部导航栏navigationbar的颜色 getWindow().setNavigationBarColor(Color.BLUE); //写法一 getWindow().setNavigationBarColor(getResources().getColor(R.color.black_12));//写法二

Android应用底部导航栏(选项卡)实例

现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图: 其中各个类的作用以及资源文件就不详细解释了,还有资源图片(在该Demo中借用了其它应用程序的资源图片)也不提供了,大家可以自行更换自己需要的资源图片.直接上各个布局文件或各个类的代码: [1]  res/layout目录下的 maintabs.xml 源码: <?xml version="1.0

Android应用-底部导航栏的使用

目录 1. 设计底部导航栏页面 1.1. 创建必须的文件夹 1.2. 设计主页面 2. 设计逻辑函数 3. 项目展示 底部导航栏是基于Bottom Navigation Bar 插件使用的 这个插件包裹在com.android.support:design:28.0.0,必须引入 1. 设计底部导航栏页面 1.1. 创建必须的文件夹 在res下创建color和menu文件夹 color文件夹: 用于存放导航栏的个性化颜色 menu文件夹: 用于存放导航栏的子项 1.2. 设计主页面 首先设计子项

android实现底部导航栏和顶部导航栏(相当于网页上的一级菜单和二级菜单)

直接采用图片进行导航,实现activity跳转,虽然功能实现了,但是界面实在太丑,所以采用顶部导航栏和底部导航栏进行控制,在这个学习的过程中,发现了很多好的资料,不仅对控件进行了详细的讲解和演示,而且还附带源码以供下载.再次记录,供大家参考学习: 1.http://www.linuxidc.com/Linux/2012-07/66327.htm 2.http://blog.csdn.net/yalinfendou/article/details/44727299 3.http://blog.cs

找呀志_往来(6)_仿微通道底部导航栏

效果如下面的 使用TabHost布局,并使用单选button组和FrameLayout相结合 布局文件代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:la

关于在Android中如何设置底部导航栏

Android应用底部导航栏(选项卡)实例 现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图:   其中各个类的作用以及资源文件就不详细解释了,还有资源图片(在该Demo中借用了其它应用程序的资源图片)也不提供了,大家可以自行更换自己需要的资源图片.直接上各个布局文件或各个类的代码: [1]  res/layout目录下的maintabs.xml 源码

Android仿小米商城底部导航栏之二(BottomNavigationBar、ViewPager和Fragment的联动使用)

简介 在前文<Android仿小米商城底部导航栏(基于BottomNavigationBar)>我们使用BottomNavigationBar控件模仿实现了小米商城底部导航栏效果.接下来更进一步的,我们将通过BottomNavigationBar控件和ViewPager空间的联动使用来实现主界面的滑动导航. 导航是移动应用最重要的方面之一,对用户体验是良好还是糟糕起着至关重要的作用.好的导航可以让一款应用更加易用并且让用户快速上手.相反,糟糕的应用导航很容易让人讨厌,并遭到用户的抛弃.为了打造

Android实习札记(5)---Fragment之底部导航栏的实现

Android实习札记(5)---Fragment之底部导航栏的实现 --转载请注明出处:coder-pig 在Part 4我们回顾了一下Fragment的基本概念,在本节中我们就来学习Fragment应用的简单例子吧! 就是使用Fragment来实现简单的底部导航栏,先贴下效果图: 看上去很简单,实现起来也是很简单的哈!那么接着下来就看下实现的流程图吧: 实现流程图: 看完流程图是不是有大概的思路了,那么接着就开始代码的编写吧: 代码实现: ①先写布局,布局的话很简单,一个FrameLayou

Android Fragment解析及UI底部导航栏实例

import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.view.View; import android.view.View.OnClickListener; import and