android-如何查看鳍改变图像之间的动画图像、动画、android

2023-09-06 08:02:06 作者:嗜心

这是我如何使用viewFlipper使我slidshow:

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.

我怎样才能动画呢?

感谢您

推荐答案

请参阅这些链接,他们也有动画XML的:

Refer these links, they also have the animation xml's:

链接1 &安培;链接2

示例类:

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;
    }
}

动画XML:

淡入:

<?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>

淡出:

<?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>
 
精彩推荐
图片推荐