Sto usando seguente codiceAumentare la visibilità di una vista sul Swipe utilizzando i gesti in Android
private GestureDetector.OnGestureListener mGestureListener = new GestureDetector.OnGestureListener()
{
private float lastDeltaValue;
private static final int MIN_DISTANCE = 15;
private static final int MIN_DISTANCE_Y = 25;
@Override
public boolean onDown(MotionEvent e)
{
lastDeltaValue = 0;
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e)
{
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
float startingX = (int)e1.getRawX();
float startingY = (int)e1.getRawY();
float endingX = (int)e2.getRawX();
float endingY = (int)e2.getRawY();
float deltaX = startingX - endingX;
float deltaY = startingY - endingY;
// swipe horizontal?
if(Math.abs(deltaX) > MIN_DISTANCE && Math.abs(deltaY) < MIN_DISTANCE_Y)
{
// left or right
if(deltaX > 0)
{
shouldCallBtn = SHOULD_CALL_WHERE;
if (gestureLayout.getVisibility() == View.GONE)
{
gestureLayout.setVisibility(View.VISIBLE);
gestureLayout.setAlpha(0.3f);
}
gestureText.setText(getString(R.string.option_where));
if (deltaX > lastDeltaValue)
{
if (gestureLayout.getAlpha() > 0.29 && gestureLayout.getAlpha() < 0.80)
gestureLayout.setAlpha(gestureLayout.getAlpha() + 0.1f);
}
else
{
if (gestureLayout.getAlpha() < 0.81 && gestureLayout.getAlpha() > 0.29)
gestureLayout.setAlpha(gestureLayout.getAlpha() - 0.1f);
}
Log.d("DELTA VALUES", String.valueOf(deltaX) + " == " + String.valueOf(lastDeltaValue) + " " +String.valueOf(gestureLayout.getAlpha()));
lastDeltaValue = deltaX;
}
else if(deltaX < 0)
{
shouldCallBtn = SHOULD_CALL_ONMYWAY;
if (gestureLayout.getVisibility() == View.GONE)
{
gestureLayout.setVisibility(View.VISIBLE);
gestureLayout.setAlpha(0.3f);
}
gestureText.setText(getString(R.string.option_onway));
if (deltaX > lastDeltaValue)
{
if (gestureLayout.getAlpha() > 0.29 && gestureLayout.getAlpha() < 0.80)
gestureLayout.setAlpha(gestureLayout.getAlpha() - 0.1f);
}
else
{
if (gestureLayout.getAlpha() < 0.81 && gestureLayout.getAlpha() > 0.29)
gestureLayout.setAlpha(gestureLayout.getAlpha() + 0.1f);
}
Log.d("DELTA VALUES", String.valueOf(deltaX) + " == " + String.valueOf(lastDeltaValue) + " " +String.valueOf(gestureLayout.getAlpha()));
lastDeltaValue = deltaX;
}
}
else
{
}
return false;
}
@Override
public void onLongPress(MotionEvent e)
{
gestureLayout.setVisibility(View.VISIBLE);
gestureLayout.setAlpha(0.8f);
gestureText.setText(getString(R.string.option_my_location));
sendLocBtn.performClick();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
return false;
}
};
Inizialmente GestureLayout
visibilità è GONE
. Dopo lo scorrimento la sua visibilità aumenterà da 0,3 a 0,8. Se provo a sinistra, scorri verso l'alto Aumenta l'alfa di uno View
da qualche parte sullo schermo con un testo simile a (scorrimento a sinistra) e così fa sullo swipe destro.
Questo codice sembra funzionare ma l'animazione di alfa da basso ad alto non è conforme allo standard.
Qualsiasi aiuto sarebbe utile
NOTA: Io non ho bisogno di un'animazione. Voglio che sia basato sullo sfioramento del dito
Ciao Muhammad. Quando provo a eseguire il codice, i seguenti simboli non sono definiti: "R.string.option_my_location'," R.string.option_onway', "R.string.option_where", "SHOULD_CALL_ONMYWAY'," SHOULD_CALL_WHERE', "gestureLayout', 'gestureText',' sendLocBtn' e 'shouldCallBtn'. Puoi fornire un esempio minimo, completo e verificabile (http://stackoverflow.com/help/mcve) per favore? Sarà quindi possibile riprodurre facilmente il problema che stai avendo, rendendo molto più facile fornire una buona risposta per te. –
@MartinNordholts basta sostituire quelli con qualcosa o commentarli. Esegui una visualizzazione gestureLayout che è importante per aumentare o diminuire la sua visibilità –
"Questo codice sembra funzionare ma l'animazione dell'alfa da bassa ad alta non è all'altezza dello standard." Qual è il problema? Vuoi che l'alfa sia animata mentre il colpo è in corso? – SharpEdge