ImageView捏缩放,这是图像鳍状肢内部

时间:2014-04-20 05:37:49

标签: android android-imageview

我正在使用android中的应用程序,它在Flipper内的图像视图中显示一些预设图像。我想实现缩放到这个图像视图,捏缩放。我已经实现了鳍状肢和滑动movemet来改变滑动手势上的imageview。我想现在实现捏缩放。 下面是活动的xml。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ffffffff"
        android:orientation="vertical" >

        <ViewFlipper
            android:id="@+id/view_flipper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView1"
                    style="@style/ImageTitle"
                    android:layout_height="wrap_content"
                    android:text="Alto 800" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:adjustViewBounds="true"
                    android:scaleType="matrix"
                    android:src="@drawable/alto800" />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:adjustViewBounds="true"
                    android:scaleType="matrix"
                    android:src="@drawable/cheveroletbeat" />

                <TextView
                    style="@style/ImageTitle"
                    android:text="Cheverolet Beat" />
            </RelativeLayout>
 </ViewFlipper>

继承了已实施的java代码

   public class MainActivity extends Activity {

        private static final int SWIPE_MIN_DISTANCE = 120;
        private static final int SWIPE_THRESHOLD_VELOCITY = 200;
        private ViewFlipper mViewFlipper;
        private Context mContext;
        public MediaPlayer mp ;
        @SuppressWarnings("deprecation")
        private final GestureDetector detector = new GestureDetector(
                new SwipeGestureDetector());

        int flag = 1;


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mp = MediaPlayer.create(getBaseContext(), R.raw.funtime);
            mp.setLooping(true);
            mp.start();

            mContext = this;

            mViewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);
            mViewFlipper.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(final View view, final MotionEvent event) {
                    detector.onTouchEvent(event);
                    return true;
                }
            });
   }@Override
        public void onDestroy()
        {
            super.onDestroy();
            mp.stop();
        }

        class SwipeGestureDetector extends SimpleOnGestureListener implements
                OnGestureListener {

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                    float velocityY) {

                try {
                    // right to left swipe
                    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                            && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                        mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(
                                mContext, R.anim.right_in));
                        mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(
                                mContext, R.anim.left_out));
                        mViewFlipper.showNext();
                        MediaPlayer mediaPlayer = MediaPlayer.create(
                                getBaseContext(), R.raw.vroom);
                        mediaPlayer.start();
                        return true;
                    } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                            && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                        mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(
                                mContext, R.anim.left_in));
                        mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(
                                mContext, R.anim.right_out));

                        mViewFlipper.showPrevious();
                        MediaPlayer mediaPlayer = MediaPlayer.create(
                                getBaseContext(), R.raw.vroom);
                        mediaPlayer.start();
                        return true;
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

                return false;
            }
        }
    }

请指导我捏缩放这里的部分。

0 个答案:

没有答案