一、按压缩放效果
ImageView实现按压后实现动画缩小,松手或者滑出ImageView的边界时,实现动画放大效果。
具体案例请参考去哪儿网的 【去哪儿旅行app】
首先是布局文件image_wall_layout.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dip"
android:weightSum="2" >
android:id="@+id/layout_wallitem_1"
android:layout_width="match_parent"
android:layout_height="80dip"
android:layout_marginBottom="16dip"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/ic_category_15" />
android:layout_width="16dip"
android:layout_height="match_parent" />
android:id="@+id/layout_wallitem_2"
android:layout_width="match_parent"
android:layout_height="80dip"
android:layout_marginBottom="16dip"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/ic_category_2" />
Activity代码
public class ImageWallActivity extends Activity implements OnTouchListener {
private View leftLayoutItem;
private View rightLayoutItem;
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_wall_layout);
leftLayoutItem = findViewById(R.id.layout_wallitem_1);
rightLayoutItem = findViewById(R.id.layout_wallitem_2);
leftLayoutItem.setOnTouchListener(this);
rightLayoutItem.setOnTouchListener(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
scaleToSmaller(v);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
scaleToNo