Android利用屬性動(dòng)畫實(shí)現(xiàn)優(yōu)酷菜單
利用屬性動(dòng)畫實(shí)現(xiàn)優(yōu)酷菜單,供大家參考,具體內(nèi)容如下
布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:layout_width="280dip" android:layout_height="140dip" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:id="@+id/level3" android:background="@drawable/level3" > <ImageButton android:id="@+id/c1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="6dip" android:layout_marginLeft="12dip" android:background="@drawable/channel1" /> <ImageButton android:id="@+id/c2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/c1" android:layout_marginBottom="12dip" android:layout_marginLeft="28dip" android:background="@drawable/channel2" /> <ImageButton android:id="@+id/c3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/c2" android:layout_marginBottom="6dip" android:layout_marginLeft="8dip" android:layout_toRightOf="@id/c2" android:background="@drawable/channel3" /> <ImageButton android:id="@+id/c4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_margin="6dip" android:background="@drawable/channel4" /> <ImageButton android:id="@+id/c5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/c6" android:layout_marginBottom="6dip" android:layout_marginRight="8dip" android:layout_toLeftOf="@+id/c6" android:background="@drawable/channel5" /> <ImageButton android:id="@+id/c6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/c7" android:layout_marginBottom="12dip" android:layout_marginRight="28dip" android:layout_alignParentRight="true" android:background="@drawable/channel6" /> <ImageButton android:id="@+id/c7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="6dip" android:layout_marginRight="12dip" android:layout_alignParentRight="true" android:background="@drawable/channel7" /> </RelativeLayout> <RelativeLayout android:layout_width="180dip" android:layout_height="90dip" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:id="@+id/level2" android:background="@drawable/level2" > <ImageButton android:id="@+id/search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_margin="10dip" android:background="@drawable/icon_search" /> <ImageButton android:id="@+id/menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_margin="6dip" android:background="@drawable/icon_menu" /> <ImageButton android:id="@+id/myyouku" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_margin="10dip" android:background="@drawable/icon_myyouku" /> </RelativeLayout> <RelativeLayout android:layout_width="100dip" android:layout_height="50dip" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@drawable/level1" > <ImageButton android:id="@+id/home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/icon_home" /> </RelativeLayout> </RelativeLayout>
核心代碼
package com.example.uumusic.menu;
import android.content.Context;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.example.uumusic.R;
import com.example.uumusic.fragment.base.BasePager;
import com.example.uumusic.utils.Tools;
import butterknife.ButterKnife;
import butterknife.InjectView;
/**
* Created by Administrator on 2017.06.07.0007.
*/
public class YoukuMenu extends BasePager {
@InjectView(R.id.c1)
ImageButton c1;
@InjectView(R.id.c2)
ImageButton c2;
@InjectView(R.id.c3)
ImageButton c3;
@InjectView(R.id.c4)
ImageButton c4;
@InjectView(R.id.c5)
ImageButton c5;
@InjectView(R.id.c6)
ImageButton c6;
@InjectView(R.id.c7)
ImageButton c7;
@InjectView(R.id.level3)
RelativeLayout level3;
@InjectView(R.id.search)
ImageButton search;
@InjectView(R.id.menu)
ImageButton menu;
@InjectView(R.id.myyouku)
ImageButton myyouku;
@InjectView(R.id.level2)
RelativeLayout level2;
@InjectView(R.id.home)
ImageButton home;
private boolean isLeve12 = true;
private boolean isLeve13 = true;
public YoukuMenu(Context context) {
super(context);
}
@Override
public View initView() {
View view = View.inflate(mContext, R.layout.fragment_youku, null);
ButterKnife.inject(this,view);
return view;
}
@Override
public void initData() {
//為按鈕設(shè)置點(diǎn)擊事件
home.setOnClickListener(new MyOnClickLisetner());
menu.setOnClickListener(new MyOnClickLisetner());
}
class MyOnClickLisetner implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.home:
//當(dāng)點(diǎn)擊home按鈕時(shí),開(kāi)始進(jìn)行動(dòng)畫的效果
if (isLeve12){
isLeve12 = false;
Tools.hide(level2);
if (isLeve13){
isLeve13 = false;
Tools.hide(level3,200);
}
}else {
isLeve12 = true;
Tools.show(level2);
}
break;
case R.id.menu:
if (isLeve13){
isLeve13 = false;
Tools.hide(level3);
}else {
isLeve13 = true;
Tools.show(level3);
}
break;
}
}
}
}
動(dòng)畫工具類
package com.example.uumusic.utils;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;
/**
* Created by Administrator on 2017.06.07.0007.
*/
public class Tools {
//隱藏布局
public static void hide(ViewGroup view) {
hide(view, 0);
}
//顯示布局
public static void show(ViewGroup view) {
//使用屬性動(dòng)畫實(shí)現(xiàn)菜單的旋轉(zhuǎn)
ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",180,360);
//設(shè)置動(dòng)畫時(shí)長(zhǎng)
animator.setDuration(300);
animator.start();
view.setPivotX(view.getWidth()/2);
view.setPivotY(view.getHeight());
}
//延遲隱藏
public static void hide(ViewGroup view, int i) {
ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",0,180);
//設(shè)置動(dòng)畫時(shí)長(zhǎng)
animator.setDuration(300);
//設(shè)置延遲
animator.setStartDelay(i);
animator.start();
view.setPivotX(view.getWidth()/2);
view.setPivotY(view.getHeight());
}
}
源碼:Android利用屬性動(dòng)畫實(shí)現(xiàn)優(yōu)酷菜單
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 使用【AIDL】調(diào)用外部服務(wù)的解決方法
本篇文章是對(duì)Android中使用AIDL調(diào)用外部服務(wù)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Handler實(shí)現(xiàn)倒計(jì)時(shí)功能
這篇文章主要為大家詳細(xì)介紹了Handler實(shí)現(xiàn)倒計(jì)時(shí)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-04-04
android中px和dp,px和sp之間的轉(zhuǎn)換方法
在Android開(kāi)發(fā)中dp和px,sp和px之間的轉(zhuǎn)換時(shí)必不可少的。下面腳本之家小編給大家?guī)?lái)了android中px和dp,px和sp之間的轉(zhuǎn)換方法,感興趣的朋友一起看看吧2018-06-06
Android中Activity滑動(dòng)關(guān)閉的效果
這篇文章主要介紹了Android中Activity滑動(dòng)關(guān)閉的效果,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-05-05
四種Flutter子頁(yè)面向父組件傳遞數(shù)據(jù)的方法介紹
在?Flutter?中,如果父組件需要調(diào)用子組件的方法,可以通過(guò)常用的四種方式實(shí)現(xiàn),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-01-01
Android使用Intent傳遞組件大數(shù)據(jù)
這篇文章主要介紹了Android使用Intent傳遞組件大數(shù)據(jù),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容詳情,感興趣的朋友可以參考一下2022-07-07
詳解Android App卸載后跳轉(zhuǎn)到指定的反饋?lái)?yè)面的方法
這篇文章主要介紹了Android App卸載后跳轉(zhuǎn)到指定的反饋?lái)?yè)面的方法,關(guān)鍵點(diǎn)是相關(guān)線程要判斷在目錄被消除以前作出響應(yīng),需要的朋友可以參考下2016-04-04

