• 自定义Gallery 滑动中图片自动突出显示


    package org.pskink;

    import android.content.Context;
    import android.content.res.TypedArray;
    import android.graphics.Matrix;
    import android.os.Handler;
    import android.os.Message;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.View;
    import android.view.animation.Animation;
    import android.view.animation.Transformation;
    import android.widget.AdapterView;
    import android.widget.Gallery;
    import android.widget.ImageView;
    import android.widget.AdapterView.OnItemSelectedListener;

    public class AnimatedSizingGallery extends Gallery implements OnItemSelectedListener {
    public static final String TAG = "AnimatedSizingGallery";
    private static final int MSG_ZOOM_IN = 1;
    private static final long DELAY = 100;

    private View mPrev;
    private float mAnimationScale;
    private float mAnimationOffsetY;
    private int mAnimationDuration;

    public AnimatedSizingGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSizingGallery);
    mAnimationScale = a.getFloat(R.styleable.AnimatedSizingGallery_animationScale, 2);
    mAnimationOffsetY = a.getFloat(R.styleable.AnimatedSizingGallery_animationOffsetY, 0);
    mAnimationDuration = a.getInteger(R.styleable.AnimatedSizingGallery_animationDuration, 500);
    a.recycle();
    setOnItemSelectedListener(this);
    }

    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    if (mPrev != null) {
    zoomOut();
    }
    mPrev = view;
    mGalleryHandler.removeCallbacksAndMessages(view);
    Message msg = Message.obtain(mGalleryHandler, MSG_ZOOM_IN, view);
    mGalleryHandler.sendMessageDelayed(msg, DELAY);
    }

    public void onNothingSelected(AdapterView<?> parent) {
    Log.d(TAG, "onNothingSelected called !!!");
    if (mPrev != null) {
    zoomOut();
    mPrev = null;
    }
    }

    private void zoomOut() {
    if (mGalleryHandler.hasMessages(MSG_ZOOM_IN, mPrev)) {
    mGalleryHandler.removeCallbacksAndMessages(mPrev);
    } else {
    ZoomAnimation a = (ZoomAnimation) mPrev.getAnimation();
    a.resetForZoomOut();
    mPrev.startAnimation(a);
    }
    }

    Handler mGalleryHandler = new Handler() {
    @Override
    public void dispatchMessage(Message msg) {
    if (msg.what == MSG_ZOOM_IN) {
    ImageView view = (ImageView) msg.obj;
    Animation a = new ZoomAnimation(view, 1, mAnimationScale, mAnimationOffsetY, mAnimationDuration);
    view.startAnimation(a);
    }
    }
    };

    class ZoomAnimation extends Animation {
    private float mFrom;
    private float mTo;
    private float mOffsetY;
    private int mPivotX;
    private int mPivotY;
    private float mInterpolatedTime;

    public ZoomAnimation(View v, float from, float to, float offsetY, int duration) {
    super();
    mFrom = from;
    mTo = to;
    mOffsetY = offsetY * v.getHeight();
    setDuration(duration);
    setFillAfter(true);
    mPivotX = v.getWidth() / 2;
    mPivotY = v.getHeight() / 2;
    }

    public void resetForZoomOut() {
    reset();
    mOffsetY = 0;
    mFrom = mFrom + (mTo - mFrom) * mInterpolatedTime;
    mTo = 1;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
    mInterpolatedTime = interpolatedTime;
    float s = mFrom + (mTo - mFrom) * interpolatedTime;
    Matrix matrix = t.getMatrix();
    if (mOffsetY != 0) {
    matrix.preTranslate(0, mOffsetY * interpolatedTime);
    }
    if (mTo == 1) {
    matrix.preRotate(360 * interpolatedTime, mPivotX, mPivotY);
    }
    matrix.preScale(s, s, mPivotX, mPivotY);
    }
    }
    }

    附件:https://files.cnblogs.com/shanzei/Gallery.zip

    转自:http://flyingsir-zw.iteye.com/blog/1456523

  • 相关阅读:
    SAP CRM WebClient UI的Delta处理机制介绍
    三种动态控制SAP CRM WebClient UI assignment block显示与否的方法
    SAPGUI软件里做的设置,本地操作系统保存的具体位置
    SAP CRM附件在应用服务器上的存储原理解析
    FLINK实例(2):CONNECTORS(1)如何正确使用 Flink Connector?
    shell脚本执行报错:/bin/bash^M: bad interpreter: No such file or directory
    FLINK实例(6): CONNECOTRS(5)Flink Kafka Connector 与 Exactly Once 剖析
    java.lang.IllegalStateException(Connection to remote Spark driver was lost)
    java.security.cert.CertificateNotYetValidException: NotBefore
    Hadoop问题:org.apache.hadoop.ipc.RpcException: RPC response exceeds maximum data length 错误
  • 原文地址:https://www.cnblogs.com/shanzei/p/2415642.html
Copyright © 2020-2023  润新知