Last active
December 30, 2016 00:57
-
-
Save prolificcoder/72f9a9fe6567a2e17df09bf65a601858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyFragment extends Fragment implements AppBarLayout.OnOffsetChangedListener { | |
//..... other code here | |
//Initialize appbar | |
private AppBarLayout appbar; | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
//.,. | |
appbar = (AppBarLayout) mainView.findViewById(R.id.appbar); | |
} | |
// Set the content descriptions based on the offset math | |
@Override | |
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { | |
if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) { | |
contactImage.setContentDescription(getString(R.string.cd_image_collapsed)); | |
} else if (verticalOffset == 0) { | |
contactImage.setContentDescription(getString(R.string.cd_image_expanded)); | |
} else { | |
contactImage.setContentDescription(getString(R.string.cd_image_collapsing)); | |
} | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
appbar.addOnOffsetChangedListener(this); | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
appbar.removeOnOffsetChangedListener(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment