原创:android模仿iphone 腾讯爱看文章列表放大缩小 带动画

分享到:

产品一直拿着iphone app应用的效果,来强行让android实现同样的功能,android码农表示很悲催。

 

看效果:(以图片放大缩小为例)

          

 

package controls;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import Interface.ScalingChangeListener;
import android.os.Handler;
import android.view.View;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ScalingBig {
    
    private ScalingChangeListener changeListener;
    
    public ScalingChangeListener getChangeListener() {
        return changeListener;
    }

    public void setChangeListener(ScalingChangeListener changeListener) {
        this.changeListener = changeListener;
    }

    Handler handel = new Handler();
    int oldHeight=0;
    int newHeight=0;
    
    int currentHeight=0;
    
    int topMargin=0;//根View 可变
    int topHeight=0; //根view高度 不可变
    View rootView;
    View view;
    RelativeLayout.LayoutParams rowViewParams;
    RelativeLayout.LayoutParams rootViewParas;
    int topTime;//向上移动的次数
    int topStep;//向上移动每次的步长
    
    int timeHeight=100;//每次设置高度的步长
    
    public ScalingBig(View rootView,RelativeLayout.LayoutParams rootViewParas,
            View view,RelativeLayout.LayoutParams rowViewParams
            ,int topHeight,int oldHeight,int newHeight){
        this.view=view;
        this.oldHeight=oldHeight;
        this.currentHeight=oldHeight;
        
        this.newHeight=newHeight;
        this.rowViewParams = rowViewParams;
        this.rootViewParas=rootViewParas;
        this.rootView=rootView;
        
        this.topHeight=topHeight;
        
        topTime=(newHeight-oldHeight)%timeHeight==0?(newHeight-oldHeight)/timeHeight:(newHeight-oldHeight)/timeHeight+1;
        topStep=topHeight%topTime==0?topHeight/topTime:topHeight/topTime+1;
    }
    
    public void startScaling(){
        handel.post(run);
    }
    
    private Runnable run = new Runnable() {
        
        public void run() {
            if(rowViewParams.height>=newHeight){
                handel.removeCallbacks(run);
                if(changeListener!=null){
                    changeListener.finish();
                }
            }else{
                currentHeight=currentHeight+timeHeight;
                if(topHeight>0){
                    topMargin=topMargin+topStep;
                    if(topMargin>topHeight) topMargin=topHeight;
                    rootViewParas.topMargin=-topMargin;
                    rootView.requestLayout();
                    rootView.setLayoutParams(rootViewParas);
                }
                rowViewParams.height = currentHeight;
                System.out.println("currentHeight:"+currentHeight+" rootViewParas.topMargin:"+ -topMargin);
                //view.setLayoutParams(rowViewParams);
                view.requestLayout();
                handel.postDelayed(run, 1);
            }
        }
    };
}
昵    称:
验证码: