图像视图上的缩放动画在> 4.0 Os设备中不起作用

时间:2013-10-18 07:14:20

标签: android animation gallery coverflow

我修改了Cover flow动画以创建图像的Gallery动画。

我想要更多变焦中心图像,因此我在项目适配器获取视图方法的图像视图中使用了以下动画。

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

Zoom.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以下工作,但是那些具有&gt; 4.0 OS,如S4,Nexus和S3的设备也不起作用。

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

先谢谢。

1 个答案:

答案 0 :(得分: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

        }

    }

还像在res / anim文件夹中那样制作了一个xml:

<强> RES /动画/ 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>