Code example for AbsoluteLayout

Methods: addView, setOnTouchListener

0
	 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		absoluteLayout = new AbsoluteLayout(this);
		getBundle(); 
		try{ 
			initPanel(); 
		}catch(Exception e){
			finish();
			return; 
			//¼ÓÔز»Õý³£µÄͼƬ±¨´í 
		} 
		setContentView(absoluteLayout);
		absoluteLayout.setOnTouchListener(this);
		init(); 
	} 
	 
	private void init(){ 
 
	} 
	 
	private void getBundle(){ 
		Bundle b = getIntent().getExtras();
		url_image = b.getString("url_image");
	} 
 
	private void initPanel(){ 
		if(url_image==null&&url_image.equals(""))
			return; 
		 
		DisplayMetrics dm = new DisplayMetrics();
	    getWindowManager().getDefaultDisplay().getMetrics(dm);
	    window_x =dm.widthPixels;	//³ýÈ¥×óÓÒ¼ä¸ô
	    window_y = dm.heightPixels;//³ýÈ¥ÈÎÎñÀ¸¸ß¶È,³ýÈ¥ÉÏϼä¸ô
	     
//	    Bitmap bitmap = Config.bitmapMovie.get(url_image); 
//	    Bitmap bitmap = Config_PictureMap.getBitmap(url_image); 
	    //¼ÓÔØͼƬ 
	    FileInputStream fStream=null;
		try { 
			fStream = new FileInputStream(url_image);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} 
		Bitmap bitmap = BitmapFactory.decodeStream(fStream);
	     
	     
	    width = bitmap.getWidth();
	    height = bitmap.getHeight();
	     
	    //¼ÆËãËõ·Å 
	    if(width > window_x || height > window_y){
	    	if(width>window_x){
		    	float scale = ((float) window_x) / width; // ±ÈÀý
		    	width = window_x;
		    	height = (int)(height *  scale);
	    	} 
	    	if(height>window_y - 25 ){
	    		float scale = ((float) window_y -25) / height; // ±ÈÀý
	    		width = (int)(width *  scale);
		    	height = window_y -25;
	    	} 
	    } 
	     
	    //¼ÆËãλÖà
	    int x = (window_x-10 - width)/2 + 5;
	    int y = (window_y-25-10 - height)/2 + 5;
	     
		AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(width, height, x, y);
		start_width = width;
		start_height = height;
		imageView = new ImageView(this);
		imageView.setImageBitmap(bitmap);
		absoluteLayout.addView(imageView, layoutParams);
	} 
 
	@Override 
	public boolean onTouch(View v, MotionEvent event) {