You are on page 1of 7

Material # 1

Ventana Splash
Profesor: Arn Elas HERRERA PONTE
Mtodo:
Vamos a ir agregando los componentes uno por uno a nuestra nueva interface.
Se mostrar, paso a paso, el contenido del archivo XML.
As mismo,
Se mostrar el cdigo android, que se debe escribir para controlar a cada
componente de la interface.
Nota: Los nuevos bloques de cdigo son mostrados en color ROJO.
En resumen:
Vamos a ir agregando cada componente en el archivo XML y
Vamos a escribir el cdigo android en la clase JAVA para controlar los componentes.
Desarrollo:

PARTE I: Pantalla de Splash por tiempo


Hacar una pantalla de Splash en Android. Esta pantalla permanece durante 2 segundos y posteriormente inicia la aplicacin.

main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fondo">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="30dp"/>
</LinearLayout>
splash.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:background="@drawable/splash">
</LinearLayout>

Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tienda"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Tienda"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Main Activitity

import
import
import
import

android.app.Activity;
android.content.Intent;
android.os.Bundle;
android.os.Handler;

public class MainActivity extends Activity {


private final int SPLASH_DISPLAY_LENGTH = 3000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable(){
public void run(){
/*Pasados los dos segundos inicia la activity "Tienda"*/
Intent intent = new Intent(MainActivity.this, Tienda.class);
startActivity(intent);
/*Destruye esta*/
finish();
};
}, SPLASH_DISPLAY_LENGTH);

Tienda

import android.app.Activity;
import android.os.Bundle;
public class Tienda extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Run

Fuente

http://es.wikicode.org/index.php/Pantalla_de_Splash_en_Android_por_tiempo

PARTE II: Splash con animacin


strings.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>


<resources>
<string name="hello">Hello World</string>
<string name="app_name">Nuevas sorpresas en tu tienda Arn</string>
<string name="desc">descripcion</string>
</resources>
res\anim\fadein.xml

<?xml version="1.0" encoding="UTF-8"?>


<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="0"
android:toAlpha="1.0" />
</set>
res\anim\fadeout.xml

<?xml version="1.0" encoding="UTF-8"?>


<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="0"
android:toAlpha="0.0" />
</set>
splash.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inicio"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<ImageView
android:id="@+id/logo"
android:contentDescription="@string/desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true" >
</ImageView>
</LinearLayout>

main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fondo">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="30dp"/>
</LinearLayout>
Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tienda"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Tienda"
android:label="@string/app_name">
</activity>
</application>
</manifest>
Tienda.java

import android.app.Activity;
import android.os.Bundle;
public class Tienda extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Main Activity

package com.android.tienda;
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.content.Intent;
android.content.pm.ActivityInfo;
android.os.Bundle;
android.view.Window;
android.view.WindowManager;
android.view.animation.Animation;
android.view.animation.AnimationSet;
android.view.animation.AnimationUtils;
android.view.animation.Animation.AnimationListener;
android.widget.ImageView;

public class MainActivity extends Activity {


AnimationSet animationSet;
ImageView imagen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
imagen = (ImageView) findViewById(R.id.logo);
configurarAnimacion();
imagen.startAnimation(animationSet);
}
public void configurarAnimacion(){
animationSet = new AnimationSet(true);
Animation fadein = AnimationUtils.loadAnimation(this, R.anim.fadein);
fadein.setDuration(1000);
Animation fadeout = AnimationUtils.loadAnimation(this, R.anim.fadeout);
fadeout.setDuration(1000);
fadeout.setStartOffset(2500);
animationSet.addAnimation(fadein);
animationSet.addAnimation(fadeout);
animationSet.setStartOffset(1000);
animationSet.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
//Aqui lanzariamos la siguiente activity
/*Pasados los dos segundos inicia la activity "Tienda"*/
Intent intent = new Intent(MainActivity.this, Tienda.class);
startActivity(intent);
/*Destruye esta*/

finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
imagen.setImageResource(R.drawable.wikicode);
}
});
}

Run

Fuente

http://es.wikicode.org/index.php/Splash_en_Android_con_animaci%C3%B3n
Homework

http://www.mokasocial.com/2011/07/7-simple-useful-android-xml-animations/

You might also like