• 【Android】【自定义View】实现搜索放大镜旋转view


    直接上代码吧:

    public class SycleSearchView extends View implements  Runnable{
    	private int width=200,height=200; //画布宽高
    	private int srcId;
    	private Bitmap src=null;
    	private Context context;
    	private int left=0,top=0;
    	private int step=4;	//5
    	private boolean positive;
    	private Thread thread;
    	private boolean canStart=true;
    	private int iw,ih;//图片的宽高
    	
    	public SycleSearchView(Context context, AttributeSet attrs) {
    		super(context, attrs);
    		// TODO Auto-generated constructor stub
    		this.context=context;
    	}
    
    
    	public SycleSearchView(Context context, AttributeSet attrs, int defStyle) {
    		super(context, attrs, defStyle);
    		// TODO Auto-generated constructor stub
    		this.context=context;
    	}
    
    
    	private void init(){
    		left=0;
    		top=height/2;
    	}
    
    	/**
    	* 
    	* 方法: initXY 
    	* 描述: TODO
    	* 参数: @param x
    	* 参数: @param positive true 表示向右运动
    	* 返回: void
    	* 异常
    	*/
    	private void initXY(int x){
    		left=x;
    		top=height/2-(int) Math.sqrt(height*height/4-(width/2-x)*(width/2-x));
    		if(!positive)
    		{
    			top=height-top;
    		}
    	}
    
    	public void setSize(int width,int height){
    		this.width=width;
    		this.height=height;
    	}
    
    	public void setImgRes(int id){
    		this.srcId=id;
    		src=BitmapFactory.decodeResource(context.getResources(), srcId);
    		iw=src.getWidth();
    		ih=src.getHeight();
    	}
    
    	
    	@Override
    	protected void onDraw(Canvas canvas) {
    		// TODO Auto-generated method stub
    		super.onDraw(canvas);
    		if(src==null){
    			return;
    		}
    		canvas.drawBitmap(src, left, top, null);
    	}
    
    
    	public void startsycle(){
    		canStart=true;
    		Thread localThread = new Thread(this);
    		this.thread = localThread;
    		this.thread.start();
    	}
    
    	public void stopsycle(){
    		canStart=false;
    		if(this.thread!=null){
    			this.thread.interrupt();
    		}
    	}
    
    
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    		while(canStart){
    			if(positive){
    				if(left+step<width){
    					initXY(left+step);
    				}else{
    					positive=!positive;
    					initXY(left-step);
    				}
    			}else{
    				if(left-step>0){
    					initXY(left-step);
    				}else{
    					positive=!positive;
    					initXY(left+step);
    				}
    			}
    
    			postInvalidate();
    
    			try {
    				Thread.sleep(200);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }

    调用方法:

    Boolean test_start = false;
    
    private Button.OnClickListener clickImageButton_imageButton_search = new Button.OnClickListener()
    {
    	public void onClick(View v)
    	{
    		System.out.println("------clickImageButton_imageButton_search--------");
    			
    		test_start = !test_start;
    		if(test_start){
    			imageButton_magnifier.startsycle();
    		}
    		else{
    			imageButton_magnifier.stopsycle();
    		}			
    	}
    };
  • 相关阅读:
    关于Adobe CS3套装的"此产品的许可已停止" 的解决方案
    Activity的生命周期 二
    APICS与AX的Master Planning(二)Rescheduling Assumption 重排假设
    COMVariantType的Date类型
    APICS与AX的Master Planning(一)Phantom bill of Material 虚项
    APICS与AX的Master Planning(四)Time Fence时限(时界)
    APICS与AX的Master Planning(三)Firm Planned Orders已确认计划订单
    设定Access数据库自增长字段初始
    SQL Server数据库导入导出数据方式比较
    个性博客七款超靓天气预报免费代码
  • 原文地址:https://www.cnblogs.com/Amandaliu/p/2609761.html
Copyright © 2020-2023  润新知