如何为viewpager图像提供3d效果,还是可以为viewpager提供3d效果?

时间:2014-09-11 21:33:58

标签: android android-viewpager gallery android-imageview

我开发了一个应用程序,假设显示位于可绘制文件夹中的图像...用户可以在图像之间滑动..但是,对于Android新手我很好奇,如果这个YouTube链接中显示的效果是可能的。 。http://www.youtube.com/watch?v=52mXHqX9f3Y。然而,程序员使用了鳍状肢,我有viewpager ....所以任何代码帮助以及解释都会受到赞赏..我也看到了一些关于此事的问题,用户想要在a,b和c图像之间滑动。但是我不想达到这些效果..

以下是我的代码......

Imageadapter.java

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class ImageAdapter extends PagerAdapter {
    Context context;
    private int[] GalImages = new int[] {
        R.drawable.one,
        R.drawable.two,
        R.drawable.three,
        R.drawable.four,
        R.drawable.five
    };
    ImageAdapter(Context context){
        this.context=context;
    }
    @Override
    public int getCount() {
      return GalImages.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
      return view == ((ImageView) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
      ImageView imageView = new ImageView(context);
      int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_small);
      imageView.setPadding(padding, padding, padding, padding);
      imageView.setScaleType(ImageView.ScaleType. FIT_XY  );
      Resources r = context.getResources();
      Bitmap bmp = BitmapFactory.decodeResource(r, GalImages[position]);
      int width=200;//set your width
      int height=200;//set your height
      Bitmap resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height, true);
      Drawable d = new BitmapDrawable(r,resizedbitmap);
      Drawable[] layers = new Drawable[2];
      layers[0] = d;
      layers[1] = r.getDrawable(R.drawable.a);
      LayerDrawable layerDrawable = new LayerDrawable(layers);
      imageView.setImageDrawable(layerDrawable);
      ((ViewPager) container).addView(imageView, 0);
      return imageView;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
      ((ViewPager) container).removeView((ImageView) object);
    }
  }

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
   android:layout_height="match_parent" 
    tools:context=".MainActivity"
    android:icon="@drawable/icon" >


          <android.support.v4.view.ViewPager
          android:id="@+id/view_pager"
          android:layout_width="match_parent"
          android:layout_height="match_parent" 
         android:icon="@drawable/icon"
         />
           <ImageView
        android:id="@+id/swipe_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/swipe_left" />

    <ImageView
        android:id="@+id/swipe_right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/swipe_right" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您可以使用ObjectAnimator来获得所需的效果。

ObjectAnimator animator = (ObjectAnimator)AnimatorInflater.loadAnimator(
            [activity], R.animator.flip_0_90);
animator.setTarget(imageView);
animator.start();

然后是flip_0_90.xml:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:valueFrom="0" 
    android:valueTo="90" 
    android:propertyName="rotationY"
    android:duration="250" >

</objectAnimator>

然后在onAnimationEnd更改照片的动画上设置一个侦听器,并应用一个新动画从270度旋转到360度。