How to Create android Image slider or splash screen:
http://android-app27.blogspot.com/
Project:
Image Slider or Splash Screen
>>Create a new project name Image Slider
>>
Create New Class name SliderActivity
SliderAnctivity.java
package
com.sattar.imageslider;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.*;
import
android.view.animation.Animation;
import
android.view.animation.AnimationUtils;
import
android.widget.ImageView;
import
android.os.Handler;
import
java.util.Timer;
import
java.util.TimerTask;
import
com.techipost.imageslider.R;
public class
SliderActivity extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
private int[] IMAGE_IDS = {
R.drawable.splash0,
R.drawable.splash1, R.drawable.splash2,
R.drawable.splash3
}
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mygame);
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new
Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000; // delay for 1 sec.
int period = 8000; // repeat every 4
sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new
TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
public void onClick(View v) {
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
/**
* Helper method to start the animation on
the splash screen
*/
private void AnimateandSlideShow() {
slidingimage
= (ImageView)findViewById(R.id.ImageView3_Left);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation
rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
slidingimage.startAnimation(rotateimage);
}
}
>>>
res/create a folder name “anim” and past three xml file
>>>Cutom_ani.xml
, fadein.xml.fadein2.xml
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>
>>> fadein.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>
>>>> fadein2.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>
>>> Create a layout mygame.xml
>>> mygame.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"></TextView>
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Exit"
android:onClick="onClick"
/>
<ImageView
android:id="@+id/ImageView3_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
></ImageView>
</LinearLayout>
>>>
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techipost.imageslider"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name="com.sattar.imageslider.SliderActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8"
/>
</manifest>
>>>> Values/color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color
name="logo_color">#FFFF0F</color>
<color
name="version_color">#f0f0f0</color>
<color
name="version_bkgrd">#1a1a48</color>
</resources>
>>> values/string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="app_name">Image Slider by
android-app27.blogspot.com</string>
<string
name="help">Help Screen</string>
<string
name="menu">Main Menu Screen</string>
<string
name="splash">Splash Screen</string>
<string
name="settings">Settings Screen</string>
<string
name="game">Game Screen</string>
<string
name="scores">Scores Screen</string>
<string
name="app_logo_top">Image Slider</string>
<string
name="app_logo_bottom">DONE THAT!</string>
<string
name="app_version_info">Version
1.0.0\nCopyright © 2014 android-app27.blogspot.com. All Rights Reserved.
</string>
</resources>
>>> Values/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="app_name">Image Slider by
android-app27.blogspot.com</string>
<string
name="help">Help Screen</string>
<string
name="menu">Main Menu Screen</string>
<string
name="splash">Splash Screen</string>
<string
name="settings">Settings Screen</string>
<string
name="game">Game Screen</string>
<string
name="scores">Scores Screen</string>
<string
name="app_logo_top">Image Slider</string>
<string
name="app_logo_bottom">DONE THAT!</string>
<string
name="app_version_info">Version 1.0.0\nCopyright
© 2014 android-app27.blogspot.com. All Rights Reserved.
</string>
</resources>
N.b: I hope it will work, first understand the code,
than implement it , if you face any problem comment it I will try to solution
it, thank you.
No comments:
Post a Comment