android


android- How to animate between view flipper change images


this is how I made my slidshow by using viewFlipper :
private void gallery() {
imageViewFlipper = (ViewFlipper) findViewById(R.id.main_flipper);
File sdcardPath = new File(Environment.getExternalStorageDirectory().getPath() + "/Pictures/picFolder");
String sdcard = sdcardPath .getPath();
setImagesToFlipper(imageViewFlipper, sdcardPath);
runnable = new Runnable() {
public void run() {
handler.postDelayed(runnable, 3000);
imageViewFlipper.showNext();
}
};
handler = new Handler();
handler.postDelayed(runnable, 500);
}
private void setImagesToFlipper(ViewFlipper flipper, File sdcardPath) {
int imageCount = sdcardPath.listFiles().length;
for (int count = 0; count < imageCount - 1; count++) {
ImageView imageView = new ImageView(this);
Bitmap bmp = BitmapFactory.decodeFile(sdcardPath.listFiles()[count].getAbsolutePath());
imageView.setImageBitmap(bmp);
flipper.addView(imageView);
}
}
I need to animate between changing the images , Now ,it just changes the images suddenly and it doesn't look good.
How can I animate it ?
thanks you
Refer these links, they also have the animation xml's:
Link 1 &
Link 2
Example Class:
public class ViewFlipperMainActivity extends Activity
{
private ViewFlipper viewFlipper;
private float lastX;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.view_flipper_main);
viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
}
// Method to handle touch event like left to right swap and right to left swap
public boolean onTouchEvent(MotionEvent touchevent)
{
switch (touchevent.getAction())
{
// when user first touches the screen to swap
case MotionEvent.ACTION_DOWN:
{
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
// if left to right swipe on screen
if (lastX < currentX)
{
// If no more View/Child to flip
if (viewFlipper.getDisplayedChild() == 0)
break;
// set the required Animation type to ViewFlipper
// The Next screen will come in form Left and current Screen will go OUT from Right
viewFlipper.setInAnimation(this, R.anim.in_from_left);
viewFlipper.setOutAnimation(this, R.anim.out_to_right);
// Show the next Screen
viewFlipper.showNext();
}
// if right to left swipe on screen
if (lastX > currentX)
{
if (viewFlipper.getDisplayedChild() == 1)
break;
// set the required Animation type to ViewFlipper
// The Next screen will come in form Right and current Screen will go OUT from Left
viewFlipper.setInAnimation(this, R.anim.in_from_right);
viewFlipper.setOutAnimation(this, R.anim.out_to_left);
// Show The Previous Screen
viewFlipper.showPrevious();
}
break;
}
}
return false;
}
}
Animation Xml:
Fade In:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="2000"
/>
</set>
Fade Out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
/>
</set>
in_from_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="1400" />
</set>
in_from_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="1400" />
</set>
out_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="1400"/>
</set>
out_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="1400"/>
</set>

Related Links

Android Studio 2.1 RC fail to run with instant run disable
CustomView - Clear canvas thanks to setImageResource 0
Android - How to inflate xml in onCreate( )
Fragments overlap after transaction
Android RecyclerView move item to end of View
Android. Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
ionic/cordova home screen widget (Android)
“Error:Invalid keystore format” when I'm trying to build a sample
What changes we need to do in the android application to make it multiwindow application?
In RecycleView onScrolling images are flickering
Android: How to include phone number on Intent.createChooser activity for native SMS option
Resize image from sd card and save
start NFC exchanges on android python kivy platform
Error when deleting an item from listview in android
Tag tag = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_TAG);
How to get records based on one column in sqlite3 in android

Categories

HOME
search
google-cloud-platform
hyperlink
fuelux
string
forms
angular2-material
zend-framework
jsf-2.2
spring-data-redis
owl-carousel
ms-access-2016
tivoli
regular-language
zip
settings
azure-container-service
openpyxl
ibeacon-android
android-securityexception
startup
resultset
why3
datastage
google-form
speech-synthesis
radgridview
selenium-ide
bitnami
event-sourcing
azure-iot-hub
package.json
database-connection
undertow
parcelable
joptionpane
mongoid6
flask-sqlalchemy
gmock
draft-js-plugins
jackson-modules
paperjs
subclass
uitapgesturerecognizer
corenlp-server
mailkit
getpixel
fossil
jpad
reactivekit
railstutorial.org
chef-solo
news
numberpicker
postgresql-8.4
vaadin-charts
monkey-testing
optimizely
pom.xml
libgphoto2
fclose
launchctl
posixct
aquamacs
reindex
yii2-user
git-flow
sundials
reachability
choice
smartfoxserver
preprocessor
windows-azure-queues
synonym
tooleap
lua-telegram-bot
dbamp
kiosk
sklearn-pandas
cortex-m
realsense
httpruntime.cache
terracotta
jdk1.7
keyup
telepat
user-permissions
showdialog
jbake
jama
reflector
decoupling
mt4j
c++builder-xe5
code-duplication
modular
mongohq
cmmi
workitem
merb
cardreader
alice
booksleeve
midlet
qtconcurrent
xcode3.2
rmiregistry
thttpd
hibernateexception
agility.js
denied
google-floodlight
django-paypal
interprocess
qtabbar
filesystemobject
asynchronous-wcf-call

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App