0

프로젝트에 BottomNavigationView을 추가했으며 메뉴 항목 중 하나에 애니메이션을 추가하고 싶습니다. 이 애니메이션은 기본적으로 이미지 시퀀스 인 AnimationDrawable입니다. 다음과 같은 작업을 수행했으나 작동하지 않았습니다.이 작업을 수행 할 수있는 방법이나 시도 할 수있는 방법에 대한 아이디어가 있습니까?AnimationDrawable을 아래쪽에 추가합니다 .NavigationView

main_activity.xml :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/lytMain" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/lytContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="?attr/actionBarSize" /> 

    <android.support.design.widget.BottomNavigationView 
     android:id="@+id/nav" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_alignParentBottom="true" 
     android:background="@color/white" 
     app:menu="@menu/menu" /> 

</RelativeLayout> 

menu.xml :

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <item 
     android:id="@+id/menShow" 
     android:enabled="true" 
     android:icon="@drawable/headphones" 
     android:title="@string/menu_listen" 
     app:showAsAction="ifRoom" /> 
    <item 
     android:id="@+id/menSearch" 
     android:enabled="true" 
     android:icon="@drawable/search" 
     android:title="@string/menu_search" 
     app:showAsAction="ifRoom" /> 

    <item 
     android:id="@+id/menPlay" 
     android:enabled="true" 
     android:icon="@drawable/play_anim" 
     android:title="@string/menu_play" 
     app:showAsAction="ifRoom" /> 
</menu> 

play_anim.xml :

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/play_anim" 
    android:oneshot="false"> 
    <item 
     android:drawable="@drawable/vis_f1" 
     android:duration="100" /> 
    <item 
     android:drawable="@drawable/vis_f2" 
     android:duration="100" /> 
    <item 
     android:drawable="@drawable/vis_f3" 
     android:duration="100" /> 
    <item 
     android:drawable="@drawable/vis_f4" 
     android:duration="100" /> 
    <item 
     android:drawable="@drawable/vis_f5" 
     android:duration="100" /> 
    <item 
     android:drawable="@drawable/vis_f6" 
     android:duration="100" /> 
    <item 
     android:drawable="@drawable/vis_f7" 
     android:duration="100" /> 
</animation-list> 

MainActivity.java :

BottomNavigationView bottomView = (BottomNavigationView) findViewById(R.id.nav); 

MenuItem menuItem = (MenuItem) bottomView.findViewById(R.id.menPlay); 

AnimationDrawable animation = (AnimationDrawable)menuItem.getIcon(); 

animation.start(); 
,

결과는 3 개의 정적 이미지가 포함 된 메뉴입니다. 이제 그 중 하나만 움직이게하고 싶습니다.

어떤 도움을 주셔서 감사합니다. 미리 감사드립니다.

답변

0

본인에게 회신 드리겠습니다. 꽤 간단하고 강력 ButtomBar,하지만 내 문제가하고있는 해결 방법 다음 : 나는 BottomNavigationBar에 대한 타사 라이브러리를 사용하여 솔루션을 발견했습니다

MainActivity.java :

private AppCompatImageView appCompatImageView; 
private AnimationDrawable animationDrawable; 
private BottomBar navBottom; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    navBottom = (BottomBar) findViewById(R.id.navBottom); 

    appCompatImageView = (AppCompatImageView) navBottom.getTabAtPosition(Constants.BOTTOM_BAR_ANIMATION).getChildAt(0); 
    animationDrawable = (AnimationDrawable) appCompatImageView.getDrawable(); 

    if(shouldStartAnimation()) 
    { 
     if(!animationDrawable.isRunning()) 
     { 
      animationDrawable.start(); 
     } 
    } 
    else 
    { 
     animationDrawable.stop(); 
    } 
} 

public boolean shouldStartAnimation() 
{ 
    //Add some condition in here 
    return true; 
} 

main_activity. XML :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/lytMain" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<FrameLayout 
    android:id="@+id/lytContent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="?attr/actionBarSize" /> 

<com.roughike.bottombar.BottomBar 
    android:id="@+id/navBottom" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:layout_alignParentBottom="true" 
    android:background="@color/black" 
    app:bb_activeTabColor="@drawable/sbs_menu_selector" 
    app:bb_behavior="iconsOnly" 
    app:bb_tabXmlResource="@xml/bottombar_items" /> 

나는 AppCompatImageView에 메뉴 항목의 그리기를 주조 한 다음 animationDrawa는 얻을 수 그것은 간단합니다. appCompatImageView.getDrawable()을 사용하면 간단히 수행 할 수 있습니다. 필요한 경우 애니메이션 드로어 블을 시작/중지 할 수 있습니다.

shouldStartAnimation은 조건을 배치해야한다는 점에 유의하십시오.

희망이 있으면 도움이 될 수 있습니다.

추신 : 감사합니다 roughike 유용한 라이브러리 네.