|
||
|
|
|
|||||||
| Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android |
![]() |
|
|
Herramientas |
|
#1
|
||||
|
||||
|
problema animaciones
Buenas compañeros tengo un problemilla con unas animaciones...
Resulta que tengo dos texview en los cuales uso una animación para que aparezcan uno de izquierda a derecha y el otro viceversa. Los anim son estos: Código:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-50%p"
android:toXDelta="0"
android:duration = "1000"/>
</set>
Código:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p"
android:toXDelta="0"
android:duration = "1000"/>
</set>
Código:
public class IntroActivity extends AppCompatActivity {
private TextView textIntro1;
private TextView textIntro2;
private TextView textIntro3;
private final int DURACION_SPLASH = 3000;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
textIntro1=(TextView)findViewById(R.id.textIntro1);
textIntro2=(TextView)findViewById(R.id.textIntro2);
textIntro3=(TextView)findViewById(R.id.textpro);
Animation t1= AnimationUtils.loadAnimation(this,R.anim.anim_derecha);
Animation t2= AnimationUtils.loadAnimation(this,R.anim.anim_izquierda);
Animation t3= AnimationUtils.loadAnimation(this,R.anim.anim_fadeout);
textIntro1.startAnimation(t1);
textIntro2.startAnimation(t2);
textIntro3.startAnimation(t3);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(IntroActivity.this, Inicio_Activity.class);
startActivity(intent);
finish();
}
;
}, DURACION_SPLASH);
}
Vídeo con la animación: Última edición por rafaxplayer Día 07/08/15 a las 08:41:04. |
|
|
|
#2
|
||||
|
||||
|
Hola, yo te recomendaria que uses un objectAnimator, son mucho mejores en mi opinion, que las animaciones antiguas y además si quieres dar soporte a dispositivos 3.0- tienes a Nineoldandroids.
|
|
#3
|
||||
|
||||
|
gracias por la respuesta , he usado objectanimator y el resultado a sido el mismo que con animation.
|
|
#4
|
||||
|
||||
|
Entonces es problema de tiempos de ejecución, es el caso de mi telefono, un Galaxy ace (
) en este terminal Flappy Bird es algo lento, en cambio en un Xperia es mucho mas rapido o normal, si me equivoco me gustaria invocar a kriogeN o mocelet para corregirme, saludos.
|
|
#5
|
||||
|
||||
|
Usando ObjectAnimator no deberías tener ningún problema, yo he usado ObjectAnimator con NineOldAndroids en dispositivos muy antiguos (tan antiguos que no tenían ni HoneyComb) y las animaciones iban perfectas.
En cambio el sistema antiguo de animaciones (AnimationUtils, etc) es muy muy malo, incluso en dispositivos modernos a veces las animaciones tardan en ejecutarse o van a tirones. |
|
#6
|
||||
|
||||
|
Bueno he probado de todo y el efecto queda igual, se traba...
Aquí os dejo el code con objectanimator haber si veis algo... Código:
textIntro1=(TextView)findViewById(R.id.textIntro1);
textIntro2=(TextView)findViewById(R.id.textIntro2);
textIntro3=(TextView)findViewById(R.id.textpro);
ObjectAnimator translateX1 = ObjectAnimator.ofFloat(textIntro1, "translationX",-100,0);
ObjectAnimator translateX2 = ObjectAnimator.ofFloat(textIntro2, "translationX",100,0);
final ObjectAnimator fadeout = ObjectAnimator.ofFloat(textIntro3, "Alpha",0.0f,1.0f);
fadeout.setDuration(1000).addListener(new Animator.AnimatorListener() {
@override
public void onAnimationStart(Animator animation) {
}
@override
public void onAnimationEnd(Animator animation) {
Intent intent = new Intent(IntroActivity.this, Inicio_Activity.class);
startActivity(intent);
finish();
}
@override
public void onAnimationCancel(Animator animation) {
Intent intent = new Intent(IntroActivity.this, Inicio_Activity.class);
startActivity(intent);
finish();
}
@override
public void onAnimationRepeat(Animator animation) {
}
});
fadeout.setInterpolator(new AccelerateInterpolator());
translateX1.setInterpolator(new LinearInterpolator());
translateX1.setDuration(1000);
translateX2.setInterpolator(new LinearInterpolator());
translateX2.setDuration(1000).addListener(new Animator.AnimatorListener() {
@override
public void onAnimationStart(Animator animation) {
}
@override
public void onAnimationEnd(Animator animation) {
fadeout.start();
}
@override
public void onAnimationCancel(Animator animation) {
Intent intent = new Intent(IntroActivity.this, Inicio_Activity.class);
startActivity(intent);
finish();
}
@override
public void onAnimationRepeat(Animator animation) {
}
});
translateX2.start();
translateX1.start();
|