我修改了封面流动画来为图像创建画廊动画。
我想要更多缩放中心图像,因此我在Item Adapter的get View方法中使用图像视图上的以下动画。
Animation grow = AnimationUtils.loadAnimation(getContext(), R.anim.zoom);
ImgView.startAnimation(grow);
缩放.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/decelerate_interpolator" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="100"
android:toXScale="1.18"
android:toYScale="1.18" />
</set>
物品适配器
在这里,我是位于中心的那些图像的缩放动画。
int sel_pos;
public class ImageAdapter extends BaseAdapter
{
private Context mContext;
private Integer[] UnselectedImage = {
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.f
};
private Integer[] selectedImage =
{
R.drawable.a_sel,
R.drawable.b_sel,
R.drawable.c_sel,
R.drawable.d_sel,
R.drawable.e_sel,
R.drawable.f_sel,
};
public ImageAdapter(Context c)
{
mContext = c;
}
public int getCount() {
return selectedImage.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressWarnings("deprecation")
public View getView(int position, View convertView, ViewGroup parent)
{
**Animation grow = AnimationUtils.loadAnimation(this, R.anim.zoom);**
final ImageView i = new ImageView(mContext);
i.refreshDrawableState();
i.setDrawingCacheEnabled(false);
i.setAdjustViewBounds(true);
Log.e("position==", ""+position);
if(sel_pos==position)
{
i.setImageResource(selectedImage[position]);
**i.startAnimation(grow);**
}
else
{
i.setImageResource(UnselectedImage[position]);
}
i.setLayoutParams(new CoverFlow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
return i;
}
private class SelectListener implements AdapterView.OnItemSelectedListener
{
public SelectListener(Context c)
{
}
@SuppressWarnings("deprecation")
public void onItemSelected(AdapterView<?> parent, View v, int position,long id)
{
Log.e("Changed----->", "" + position);
// Zoom the new selected view
try
{
sel_pos = position;
coverImageAdapter.notifyDataSetChanged();
} catch (Exception animate)
{
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
此动画完全可以在 4.0 以下运行,但对于具有 >4.0 操作系统的设备(如 S4、Nexus 和 S3)也不起作用。
如果任何人有想法,请帮助。
提前致谢。