Vous êtes sur la page 1sur 2

ANDROID CDIGOS PARTE I Animacin(res/anim): FADE_IN.XML <?xml version="1.0" encoding="utf-8" ?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <alpha android:fromAlpha="0.0" android:toAlpha="1.

0" android:duration="2500"> </alpha> </set>

Layout(res/layout): SPLASH.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="@android:color/black"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/TextViewTopTitle" android:text="@string/app_logo_top" android:textColor="@color/logo_color" android:layout_gravity="center_vertical|center_horizontal" android:gravity="top|center" android:textSize="@dimen/logo_size" /> <TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*" android:layout_height="wrap_content" android:layout_width="fill_parent"> <TableRow android:id="@+id/TableRow01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal"> <ImageView android:id="@+id/ImageView2_Left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:src="@drawable/splash1" /> <ImageView android:id="@+id/ImageView2_Right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:src="@drawable/splash2" /> </TableRow> <TableRow android:id="@+id/TableRow02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal"> <ImageView android:id="@+id/ImageView3_Left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:src="@drawable/splash3" /> <ImageView android:id="@+id/ImageView3_Right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:src="@drawable/splash4" /> </TableRow> </TableLayout> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/TextViewBottomTitle" android:text="@string/app_logo_bottom" android:textColor="@color/logo_color" android:gravity="center" android:textSize="@dimen/logo_size" /> <TextView android:id="@+id/TextViewBottomVersion" android:text="@string/app_version_info" android:textSize="@dimen/version_size" android:textColor="@color/version_color" android:background="@color/version_bkgrd" android:layout_height="fill_parent" android:lineSpacingExtra="@dimen/version_spacing"

Animacin(res/anim): FADE_IN2.XML <?xml version="1.0" encoding="utf-8" ?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2500" android:startOffset="2500"> </alpha> </set> Animacin(res/anim): CUSTOM_ANIM.XML <?xml version="1.0" encoding="utf-8" ?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="2000" /> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000"> </alpha> <scale android:pivotX="50%" android:pivotY="50%" android:fromXScale=".1" android:fromYScale=".1" android:toXScale="1.0" android:toYScale="1.0" android:duration="2000" /> </set>

android:layout_width="fill_parent" android:layout_gravity="center_vertical|center_horizontal" android:gravity="center" /> </LinearLayout> } Clase: QUIZSPLASHACTIVITY.XML package com.android.triviagame; import import import import import import import import import android.content.Intent; android.os.Bundle; android.view.animation.Animation; android.view.animation.AnimationUtils; android.view.animation.LayoutAnimationController; android.view.animation.Animation.AnimationListener; android.widget.TableLayout; android.widget.TableRow; android.widget.TextView;

TableLayout table = (TableLayout) findViewById(R.id.TableLayout01); for (int i = 0; i < table.getChildCount(); i++) { TableRow row = (TableRow) table.getChildAt(i); row.setLayoutAnimation(controller); } @Override protected void onPause() { super.onPause(); // Stop the animation TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle); logo1.clearAnimation(); TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle); logo2.clearAnimation(); TableLayout table = (TableLayout) findViewById(R.id.TableLayout01); for (int i = 0; i < table.getChildCount(); i++) { TableRow row = (TableRow) table.getChildAt(i); row.clearAnimation(); } } @Override protected void onResume() { super.onResume(); // Start animating at the beginning so we get the full splash screen // experience startAnimating(); } }

public class QuizSplashActivity extends QuizActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); startAnimating(); } /** * Helper method to start the animation on the splash screen */ private void startAnimating() { // Fade in top title TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle); Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in); logo1.startAnimation(fade1); // Fade in bottom title after a built-in delay. TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle); Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2); logo2.startAnimation(fade2); // Transition to Main Menu when bottom title finishes animating fade2.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation animation) { // The animation has ended, transition to the Main Menu screen startActivity(new Intent(QuizSplashActivity.this, QuizMenuActivity.class)); QuizSplashActivity.this.finish(); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { } }); // Load animations for all views within the TableLayout Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim); LayoutAnimationController controller = new LayoutAnimationController( spinin);

Archivo de Manifiesto: AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.triviagame" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".QuizSplashActivity" 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="QuizActivity"></activity> <activity android:name="QuizGameActivity"></activity> <activity android:name="QuizHelpActivity"></activity> <activity android:name="QuizMenuActivity"></activity> </application> </manifest>

Vous aimerez peut-être aussi