Ho bisogno di sapere quando CollapsingToolbar dalla libreria di progettazione materiale è compresso.Come posso determinare che CollapsingToolbar sia compresso?
risposta
UPDATE: Dal momento che le versioni di supporto di 23.1.1+ il problema non c'è più, non c'è bisogno di usare l'ascoltatore e disattivare il layout di aggiornamento colpo , funzionerà come dovrebbe (link).
Implementare AppBarLayout.OnOffsetChangedListener ascoltatore sul AppBarLayout
AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(this);
e verificare se offset è 0, cioè la barra degli strumenti è completamente espanso.
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int offset)
{
if (offset == 0)
{
// Fully expanded
}
else
{
// Not fully expanded or collapsed
}
}
Date un'occhiata su questo github gist
public class MyAppBarLayout extends AppBarLayout
implements AppBarLayout.OnOffsetChangedListener {
private State state;
private OnStateChangeListener onStateChangeListener;
public MyAppBarLayout(Context context) {
super(context);
}
public MyAppBarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!(getLayoutParams() instanceof CoordinatorLayout.LayoutParams)
|| !(getParent() instanceof CoordinatorLayout)) {
throw new IllegalStateException(
"MyAppBarLayout must be a direct child of CoordinatorLayout.");
}
addOnOffsetChangedListener(this);
}
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset == 0) {
if (onStateChangeListener != null && state != State.EXPANDED) {
onStateChangeListener.onStateChange(State.EXPANDED);
}
state = State.EXPANDED;
} else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
if (onStateChangeListener != null && state != State.COLLAPSED) {
onStateChangeListener.onStateChange(State.COLLAPSED);
}
state = State.COLLAPSED;
} else {
if (onStateChangeListener != null && state != State.IDLE) {
onStateChangeListener.onStateChange(State.IDLE);
}
state = State.IDLE;
}
}
public void setOnStateChangeListener(OnStateChangeListener listener) {
this.onStateChangeListener = listener;
}
public interface OnStateChangeListener {
void onStateChange(State toolbarChange);
}
public enum State {
COLLAPSED,
EXPANDED,
IDLE
}
}
Hai ragione, ho aggiunto il codice pertinente alla domanda. –
Funziona elegantemente @EdyBolos grazie mille per la condivisione. Flawless! – Suleiman19
Come ha detto Marko, questo può essere ottenuto utilizzando la propria implementazione di OnOffsetChangedListener.
AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) {
// Collapsed
} else if (verticalOffset == 0) {
// Expanded
} else {
// Somewhere in between
}
}
}););
Questo dovrebbe essere la risposta accettata! –
- 1. Come determinare che un array sia parte di un altro?
- 2. Che cos'è "JSON compresso"?
- 3. C# Come posso verificare che un file sia jpeg?
- 4. Android come posso attendere che un servizio sia effettivamente connesso?
- 5. Come posso ottenere che la mia collisione sia più solida?
- 6. Come posso verificare che "qualcosa" sia un hash in Perl?
- 7. Come posso evitare che ResultSet sia un'eccezione chiusa in Java?
- 8. Come posso assicurarmi che strtol() sia ritornato correttamente?
- 9. Come posso eseguire sia nginx che apache insieme su Ubuntu
- 10. Come posso attendere che un elemento sia selezionabile in WebDriverJS?
- 11. Come posso aspettare che la pagina sia pronta in PhantomJS?
- 12. Come posso garantire che il comportamento illegale non sia eseguibile?
- 13. Come posso creare un NSFont sia grassetto che corsivo?
- 14. Come posso verificare che un'applet java sia caricata usando javascript?
- 15. Come posso configurare expressjs per gestire sia http che https?
- 16. Come posso visualizzare un contenuto di file compresso
- 17. Come posso sfruttare sia State sia Writer in haskell?
- 18. Come posso estrarre un archivio compresso in Perl?
- 19. Come verificare che un JCheckBox sia selezionato?
- 20. Come visualizzare sia ActionBar normale che split?
- 21. come verificare che mod_deflate sia abilitato in apache?
- 22. enumerateKeysAndObjectsUsingBlock: posso essere sicuro che sia chiamato sullo stesso thread?
- 23. Posso verificare che una classe sia * non * predefinita costruibile?
- 24. Controllare che Solidworks sia installato?
- 25. Come posso determinare l'accessibilità di un'istanza MemberInfo?
- 26. Come posso determinare è cifra Numero pari?
- 27. Come posso determinare quando viene visualizzato UICollectionViewCell?
- 28. Come posso determinare l'angolo del dispositivo?
- 29. Posso scrivere un functor C++ che accetta sia un puntatore raw sia un puntatore intelligente?
- 30. Come posso richiedere che un parametro generico sia un enum che implementa un'interfaccia?
Completamente espanso == 0, questa risposta non è corretta – Atieh
@Atieh per spiegarlo ulteriormente, quando la barra degli strumenti comprendente è completamente espansa il valore di offset è uguale a zero (offset == 0) –
Ho cambiato la condizione if in verticaleOffset < -710' quindi il problema risolto. non elegante ma funziona –