Mathias
Mathias

Reputation: 3981

Can i disable animations on Preference Screen?

I'm using Android PreferenceScreen. One screen is to be shown only for administrators.

Therefor, in my fragment onResume, i have a call:

adminScreen.setVisible(user.isAdmin());//Preference

However when the fragment is shown, the preference is first shown, then there's a short aninmation where the row disappears vertically, and the rows under it are shifted up.

I would like the row to disappear instantly, but can't see how i can make it happen. There are no methods i can see, and the android:animateLayoutChanges has no effect anywhere in my preferences.xml

Does anyone know if there is a way to disable this animation?

Upvotes: 5

Views: 1141

Answers (2)

ARLabs
ARLabs

Reputation: 1524

With the supposition that you are using a PreferenceFragmentCompat, you can avoid initial animation calling adminScreen.setVisible() before the onResume. If you do that just after the setPreferencesFromResource() or the setPreferenceScreen(), the animation would not be done.

Upvotes: 0

ballzak
ballzak

Reputation: 708

Disable the animations on the RecycleView it's using to display the preferences:

  @Override
  public RecyclerView onCreateRecyclerView (LayoutInflater inflater, ViewGroup parent, Bundle state) {
    final RecyclerView view = super.onCreateRecyclerView(inflater, parent, state);
    view.setItemAnimator(null);
    view.setLayoutAnimation(null);
    return view;
  }

However the preference to be removed will still flash briefly, so a best solution is to initially hide them in XML using app:isPreferenceVisible="false", and then show them when needed using setVisible(true)

Upvotes: 4

Related Questions