Diseño de Slidedown y slideup con animación


¿Cómo puedo mostrar un diseño en el centro con slideUp cuando presiono el botón, y presiono de nuevo para ocultar ... slideDown en ANDROID

Ayúdame con eso, thnkss

Author: Kling Klang, 2014-05-29

4 answers

Crear dos xml de animación en la carpeta res/anim

Slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<translate
    android:duration="1000"
    android:fromYDelta="0"
    android:toYDelta="100%" />
</set>

Slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<translate
    android:duration="1000"
    android:fromYDelta="100%"
    android:toYDelta="0" />
</set>

Cargue la animación Como el código de abajo e inicie la animación cuando desee De acuerdo con sus requisitos

//Load animation 
Animation slide_down = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.slide_down);

Animation slide_up = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.slide_up);

// Start animation
linear_layout.startAnimation(slide_down); 
 88
Author: Ando Masahashi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-19 12:59:59

Utilizo estas funciones fáciles, funciona como jquery slideUp slideDown, lo uso en una clase auxiliar, simplemente pasa tu vista:

public static void expand(final View v) {
    v.measure(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? WindowManager.LayoutParams.WRAP_CONTENT
                    : (int)(targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

public static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if(interpolatedTime == 1){
                v.setVisibility(View.GONE);
            }else{
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 18
Author: neoteknic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-20 12:19:14

Esto no funciona para mí, quiero que me guste la función jquery slideUp / slideDown, probé este código, pero solo mueve el contenido que permanece en el mismo lugar después del final de la animación, la vista debe tener una altura 0dp al inicio de slideDown y la altura de la vista (con wrap_content) después del final de la animación.

 3
Author: neoteknic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-06 07:41:17

Tenía un requisito similar en la aplicación en la que estoy trabajando. Y, encontré una biblioteca de terceros que hace un deslizarse hacia arriba, deslizarse hacia abajo y deslizarse hacia la derecha en Android.

Consulte el enlace para más detalles: https://github.com/mancj/SlideUp-Android

Para configurar la biblioteca (copiado de la parte ReadMe de su página de Github a petición):

Get slideUp library

Agregue el repositorio JitPack a su archivo de compilación. Agrégalo en tu construcción de raíz.gradle en el fin de los repositorios:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
    maven { url "https://maven.google.com" } // or google() in AS 3.0
  }
}

Agregar la dependencia (en el módulo gradle)

dependencies {
    compile 'com.github.mancj:SlideUp-Android:2.2.1'
    compile 'ru.ztrap:RxSlideUp2:2.x.x' //optional, for reactive listeners based on RxJava-2
    compile 'ru.ztrap:RxSlideUp:1.x.x' //optional, for reactive listeners based on RxJava
}

Para añadir el slideUp a tu proyecto, sigue estos tres sencillos pasos:

Paso 1:

Crear cualquier tipo de diseño

<LinearLayout
  android:id="@+id/slideView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

Paso 2:

Encuentra esa vista en tu actividad/fragmento

View slideView = findViewById(R.id.slideView);

Paso 3:

Crea un objeto slideUp y pasa en tu vista

slideUp = new SlideUpBuilder(slideView)
                .withStartState(SlideUp.State.HIDDEN)
                .withStartGravity(Gravity.BOTTOM)

                //.withSlideFromOtherView(anotherView)
                //.withGesturesEnabled()
                //.withHideSoftInputWhenDisplayed()
                //.withInterpolator()
                //.withAutoSlideDuration()
                //.withLoggingEnabled()
                //.withTouchableAreaPx()
                //.withTouchableAreaDp()
                //.withListeners()
                //.withSavedState()
                .build();

También puede consultar el proyecto de ejemplo en enlace. Me pareció muy útil.

 0
Author: sayleep,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-14 18:19:47