Us_pk Us_pk -4 years ago 44
Android Question

How to Hide/Show view in Android

WHY NOT ANY PEOPLE ANSWER TO ME???

In my application I want when collapsing

toolbar
, show toolbar but with alpha animation and Duration 600ms .

I write below code :

newsDetailAppBarLayout.setOnStateChangeListener(new ControllableAppBarLayout.OnStateChangeListener() {

@Override
public void onStateChange(ControllableAppBarLayout.State toolbarChange) {
switch (toolbarChange) {

case COLLAPSED:
toolbarTransTxt.setText("App Name");
//Show Toolbar
break;
case EXPANDED:
toolbarTransTxt.setText("");
//Hide Toolbar
break;
case IDLE: // Just fired once between switching states
break;
}
}
});


How can I Show
toolbar
with alpha animation in
case COLLAPSED
and hide this toolbar in
case EXPANDED
with alpha animation?

Answer Source

Use this code :

newsDetailAppBarLayout.setOnStateChangeListener(new ControllableAppBarLayout.OnStateChangeListener() {

        @Override
        public void onStateChange(ControllableAppBarLayout.State toolbarChange) {
            switch (toolbarChange) {
                case COLLAPSED:
                    YoYo.with(Techniques.FadeIn)
                            .duration(700)
                            .playOn(newsToolbar);
                    toolbarTransTxt.setText("App Name");
                    break;
                case EXPANDED:
                    toolbarTransTxt.setText("");
                    YoYo.with(Techniques.FadeOut)
                            .duration(700)
                            .playOn(newsToolbar);
                    break;
                case IDLE: // Just fired once between switching states
                    break;
            }
        }
    });

Before use this, you should add this lines in your build.gradle :

dependencies {
        compile 'com.android.support:support-compat:25.1.1'
        compile 'com.daimajia.easing:library:2.0@aar'
        compile 'com.daimajia.androidanimations:library:2.2@aar'
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download