仿Android印象筆記底部導覽列

來源:互聯網
上載者:User

標籤:

最近用上了印象筆記,覺得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

仿Android印象筆記底部導覽列

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.