Herramientas Android Andrews popupWindow

  introducido

  Android necesidades de pop como esto será PopupWindow usado, así que hacer esto encapsulados popupWindow herramientas,

  Ejemplo de uso

  Cada uno con un efecto diferente:

  Muestra sobre el botón

  Ver inflate1 = LayoutInflater.from (MainActivity.this) .inflate (R.layout.pop_item, null, false);

  PopUtils popUtils1 = new PopUtils (v, inflate1);

  popUtils1.showPop ();

  Botón 100 representada en la dirección de desplazamiento, hasta negativa a

  Ver inflate2 = LayoutInflater.from (MainActivity.this) .inflate (R.layout.pop_item, null, false);

  PopUtils popUtils2 = new PopUtils (v, inflate2);

  popUtils2.showPopY (100);

  Izquierda botón de cambio 100 presenta, a la derecha a negativo

  Ver inflate3 = LayoutInflater.from (MainActivity.this) .inflate (R.layout.pop_item, null, false);

  PopUtils popUtils3 = new PopUtils (v, inflate3);

  popUtils3.showPopX (100);

  Compensar hasta el botón de 100 pantallas, pantalla 100 de desplazamiento hacia la izquierda, lo contrario será cambiado a negativo

  Ver inflate4 = LayoutInflater.from (MainActivity.this) .inflate (R.layout.pop_item, null, false);

  PopUtils popUtils4 = new PopUtils (v, inflate4);

  popUtils4.showPopXY (100, 100);

  explicación relacionada

  // Obtener vista, R.layout.xxx es mostrar el contenido PopupWindow

  Ver infle = LayoutInflater.from (上下文 Context) .inflate (R.layout.xxx, null, false);

  // eventos escribir aquí PopupWindow los controles relacionados

  ...

  // instantiate

  // v: Tap / pulsación larga material de archivo de eventos y reuniones Ver

  // inflar: PopupWindow para mostrar la vista

  PopUtils popUtils = new PopUtils (V, inflarse);

  // PopupWindow pantalla

  popUtils.showPop ();

  herramientas de empaquetado

  Algunas consideraciones paquete integrado

  PopupWindow posición de la ventana definida

  Según Ver ubicación del evento emergente

  / **

  * ThirdGoddess @author

  * @Email [email protected]

  * @Github https://github.com/ThirdGoddess

  * @Date: 17/03/2020 01:42

  * /

  PopUtils clase pública {

  privada Ver v;

  popupWindow PopupWindow privado;

  private int [] ubicación;

  popupWidth int privado;

  popupHeight int privado;

  / **

  * @Param v Ver evento

  * @Param inflar elemento del cuadro de bomba

  * /

  PopUtils (Ver v, Ver inflarse) {

  this.v = v;

  popupWindow = nuevo PopupWindow (inflado, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);

  popupWindow.setBackgroundDrawable (nuevo BitmapDrawable ());

  inflate.measure (View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

  popupWidth = inflate.getMeasuredWidth ();

  popupHeight = inflate.getMeasuredHeight ();

  location = new int [2];

  v.getLocationOnScreen (ubicación);

  }

  / **

  * PopupWindow aparece sobre el evento Ver

  * /

  showPop public void () { hospitalario ginecológica Zhengzhou http://www.0371zzkd.com/

  popupWindow.showAtLocation (v, Gravity.NO_GRAVITY, (ubicación [0] + v.getWidth () / 2) - popupWidth / 2, la ubicación [1] - popupHeight);

  }

  / **

  Y-eje de desplazamiento *

  *

  * @Param offsetY Y eje de desplazamiento (positivo en el movimiento, hacia abajo negativo)

  * /

  showPopY pública vacío (int offsetY) {

  popupWindow.showAtLocation (v, Gravity.NO_GRAVITY, (ubicación [0] + v.getWidth () / 2) - popupWidth / 2, la ubicación [1] - popupHeight - offsetY);

  }

  / **

  El eje x compensados ​​*

  *

  * @Param offsetX X eje descentrado (izquierda positivo, negativo derecha)

  * /

  showPopX pública vacío (int offsetX) {

  popupWindow.showAtLocation (v, Gravity.NO_GRAVITY, (ubicación [0] + v.getWidth () / 2) - popupWidth / 2 - offsetX, ubicación [1] - popupHeight);

  }

  / **

  * Eje X y el eje Y compensado

  *

  * @Param offsetX X eje descentrado (izquierda positivo, negativo derecha)

  * @Param offsetY Y eje de desplazamiento (positivo en el movimiento, hacia abajo negativo)

  * /

  showPopXY pública vacío (int offsetX, int offsetY) {

  popupWindow.showAtLocation (v, Gravity.NO_GRAVITY, (ubicación [0] + v.getWidth () / 2) - popupWidth / 2 - offsetX, ubicación [1] - popupHeight - offsetY);

  }

  / **

  * Cerca PopupWindow

  * /

  dismissPop public void () {

  Si (null! = popupWindow) {

  popupWindow.dismiss ();

  }

  }

  }


Supongo que te gusta

Origin blog.51cto.com/14335413/2479705
Recomendado
Clasificación