3

我修改了封面流动画来为图像创建画廊动画。

我想要更多缩放中心图像,因此我在Item Adapter的get View方法中使用图像视图上的以下动画。

Animation grow = AnimationUtils.loadAnimation(getContext(), R.anim.zoom);
ImgView.startAnimation(grow);

缩放.xml

  <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true"
        android:interpolator="@android:anim/decelerate_interpolator" >

        <scale
            android:duration="500"        
            android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:startOffset="100"
            android:toXScale="1.18"
            android:toYScale="1.18" />

    </set>    

物品适配器

在这里,我是位于中心的那些图像的缩放动画。

int sel_pos;

    public class ImageAdapter extends BaseAdapter 
    {

        private Context mContext;

        private Integer[] UnselectedImage = {
                R.drawable.a,
                R.drawable.b,
                R.drawable.c, 
                R.drawable.d, 
                R.drawable.e,
                R.drawable.f
        };

        private Integer[] selectedImage = 
            {
                R.drawable.a_sel,
                R.drawable.b_sel,
                R.drawable.c_sel, 
                R.drawable.d_sel, 
                R.drawable.e_sel,
                R.drawable.f_sel,
            };



        public ImageAdapter(Context c) 
        {
            mContext = c;

        }


        public int getCount() {
            return selectedImage.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @SuppressWarnings("deprecation")
        public View getView(int position, View convertView, ViewGroup parent)
        {               
             **Animation grow = AnimationUtils.loadAnimation(this, R.anim.zoom);**    

            final ImageView i = new ImageView(mContext);            
            i.refreshDrawableState();
            i.setDrawingCacheEnabled(false);    
             i.setAdjustViewBounds(true);
            Log.e("position==", ""+position);           

            if(sel_pos==position)
            {               
                i.setImageResource(selectedImage[position]);
                **i.startAnimation(grow);**
            }
            else 
            {               
                i.setImageResource(UnselectedImage[position]);

            }       
            i.setLayoutParams(new CoverFlow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);



            BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
            drawable.setAntiAlias(true);

            return i;

        }

private class SelectListener implements AdapterView.OnItemSelectedListener 
    {   

        public SelectListener(Context c) 
        {

        }

        @SuppressWarnings("deprecation")
        public void onItemSelected(AdapterView<?> parent, View v, int position,long id) 
        {
            Log.e("Changed----->", "" + position);
            // Zoom the new selected view
            try 
            {               

                sel_pos = position;             
                coverImageAdapter.notifyDataSetChanged();



            } catch (Exception animate) 
            {

            }       

        }

        public void onNothingSelected(AdapterView<?> parent) {
        }

    }

此动画完全可以在 4.0 以下运行,但对于具有 >4.0 操作系统的设备(如 S4、Nexus 和 S3)也不起作用。

如果任何人有想法,请帮助。

提前致谢。

4

1 回答 1

3

如果我猜对了,那么试试下面的代码,它适用于所有版本。我很确定。

ZoomActivity.java

  public class ZoomInActivity extends Activity implements AnimationListener {

        ImageView imgPoster;
        Button btnStart;

        // Animation
        Animation animZoomIn;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_zoom_in);

            imgPoster = (ImageView) findViewById(R.id.imgLogo);
            btnStart = (Button) findViewById(R.id.btnStart);

            // load the animation
            animZoomIn = AnimationUtils.loadAnimation(getApplicationContext(),
                    R.anim.zoom_in);

            // set animation listener
            animZoomIn.setAnimationListener(this);

            // button click event
            btnStart.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // start the animation
                    imgPoster.startAnimation(animZoomIn);
                }
            });

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // Take any action after completing the animation

            // check for zoom in animation
            if (animation == animZoomIn) {          
            }

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

    }

还制作了一个 xml,就像您在 res/anim 文件夹中所做的那样:

res/anim/zoom_in.xml

   <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true" >

        <scale
            android:duration="1000"
            android:fromXScale="1"
            android:fromYScale="1"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="3"
            android:toYScale="3" >
        </scale>

    </set> 
于 2013-10-18T11:46:45.440 回答