понеділок, 13 серпня 2012 р.

ViewGroup.getChildStaticTransformation

Do you use method ViewGroup.getChildStaticTransformation? I know we have a new transform API, but only for android 3.0. Let me show you a short example how you can use it.


 public class MyGallery extends Gallery  
 {  
   public MyGallery(Context context)  
   {  
     super(context);  
   }  
   @Override  
   protected boolean getChildStaticTransformation(View child, Transformation t)  
   {  
     float childCenterX = child.getLeft() + child.getWidth() / 2;  
     float centerX = getWidth() / 2;  
     float scale = 1.2f - 0.8f * Math.abs(childCenterX - centerX) / centerX; // some math-magic  
     t.clear();  
     t.getMatrix().setScale(scale, scale, child.getWidth() / 2, child.getHeight() / 2);  
     return true;  
   }
}  
Result

Немає коментарів:

Дописати коментар