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.Webview is not working for tracking url.how can open this url in my activity
Android NDK Crash on Emulator
Copy and share text into Clipboard from listview
Android Fragment forgets button
IAE: Service not registered on unbindService after Service.stopSelf
Streaming microphone to RTMP (red5) and back on android
Scanning QR or barcodes on iPhone or Android in with just HTML 5
Item gets moved on ActionBar on Android 4.1.1
How to retrieve Data from curser
Synchronization between two ListViews scroll lagging
Can WindowTester be integrated with some other tool to make it work with Android?
Sencha Touch can not open camera
fragment to fragment trasaction is slow
ImageView layout_height on different screens - Android
Why the Android Studio need to download Gradle?
What does AccessibilityManager.interrupt() exactly do?

Categories

HOME
url-redirection
embedded
porting
hyperlink
string
jmeter
google-spreadsheet
angular-formly
shiro
gradient
switch-statement
jetty
banner
lanczos
opengl-es-3.0
ipmitool
stellar.js
intercom
gource
docx
internationalization
mvc-mini-profiler
solrcloud
symbols
breadth-first-search
visual-studio-extensions
pchart
qliksense
zxing
dynamically-generated
definitelytyped
moses
jquery-multiselect
android-maps
genexus-sd
magento-1.8
deltaspike
jett
openwhisk
reverse
parse-tree
alphabetical
google-knowledge-graph
recurrent-neural-network
verifiable-c
typesafe-config
chef-solo
visa
naming
microsoft-metro
jide
geotiff
identification
x-ray
corruption
arq
semantic-logging
context-sensitive-grammar
template-toolkit
testrail
usart
signalr.client
hclust
blitline
android-launcher
page.js
binomial-theorem
doctype
typemock
haskell-warp
aspectj-maven-plugin
user-permissions
adehabitathr
ejb-2.x
ssis-data-flow
sonarqube-5.0
appserver
linkedin-jsapi
human-computer-interface
jama
ebay-lms
nebula
node-blade
epiceditor
actiondispatch
virtual-pc
android-sdk-2.3
patricia-trie
xcode3.2
os.system
failing-tests
flex-mobile
gobject-introspection
cgbitmapcontextcreate
mathematical-notation
sun
perl5.12
sqlobject
flvplayback

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