Android:画廊视图中的动画?

Android:画廊视图中的动画?,android,image,android-animation,gallery,Android,Image,Android Animation,Gallery,当我使用Gallery小部件时,如何让图像在被选中时说放大&发光,在取消选中时说缩小&取消发光 我看过的所有教程都有这种效果,但我看不到 是否有某种类型的动画我必须附加到图库?您需要使用图像切换器。ImageSwitcher具有设置输入和输出动画的方法(当选择和取消选择图像,或选择和替换图像时) 有一个很好的教程,介绍如何将其与图库结合使用。希望这对您有所帮助。我设法用Gallery小部件“模拟”收缩/增长解决方案。由于他们删除了getScale(),事情变得有点复杂。我认为这根本不是最好的解决

当我使用Gallery小部件时,如何让图像在被选中时说放大&发光,在取消选中时说缩小&取消发光

我看过的所有教程都有这种效果,但我看不到


是否有某种类型的动画我必须附加到图库

您需要使用图像切换器。ImageSwitcher具有设置输入和输出动画的方法(当选择和取消选择图像,或选择和替换图像时)


有一个很好的教程,介绍如何将其与图库结合使用。

希望这对您有所帮助。我设法用
Gallery
小部件“模拟”收缩/增长解决方案。由于他们删除了
getScale()
,事情变得有点复杂。我认为这根本不是最好的解决方案,但至少我可以接受

我发现
Gallery
对焦点的管理非常糟糕。因此,第一种方法是在显示的
ImageView
上添加一个焦点更改侦听器,但没有成功。焦点是一团混乱。。。换句话说,所选图像不是当前聚焦的视图。我已经向android开发者邮件列表发送了一封关于API文档错误的邮件(关于
focusSearch()
方法和一些focuscontants)

以下是我对这个问题的解决方案:

构建动画资源以“增长”图像:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
       android:fromXScale="1.0"
       android:toXScale="1.10"
       android:fromYScale="1.0"
       android:toYScale="1.10"
       android:duration="300"
       android:pivotX="50%"
       android:pivotY="50%"
       android:interpolator="@android:anim/accelerate_decelerate_interpolator"
       android:fillAfter="false"/>
将该行添加到
ImageAdpater
对象的
getView()
方法后,您就可以在侦听器中明确标识该视图,例如:

g.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void  onItemSelected  (AdapterView<?>  parent, View  v, int position, long id) {
        Animation grow = AnimationUtils.loadAnimation(YourActivity.this, R.anim.grow);

        View sideView = parent.findViewById(position - 1);
        if (sideView != null)
           ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(150, 100));

        sideView = parent.findViewById(position + 1);
        if (sideView != null)
           ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(150, 100));

        v.startAnimation(grow);
        v.setLayoutParams(new Gallery.LayoutParams(170, 150));
    }

    public void  onNothingSelected  (AdapterView<?>  parent) {
        System.out.println("NOTHING SELECTED");

    }
    });

我实现了类似的动画,如下所示:

final Animation shrink = AnimationUtils.loadAnimation(activity, R.anim.shrink);
shrink.setFillAfter(true);

gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            // This iterates through the views which are currently displayed on screen.
            for (int k=0; k<gallery.getChildCount(); k++){
                // Do whatever else you want, here.
                // This is how you get a particular element of a view
                ImageView background = (ImageView) gallery.getChildAt(k).findViewById(R.id.menu_item_background);

                //clear animation
                gallery.getChildAt(k).clearAnimation();

            }

            // Scale the selected one
            view.startAnimation(shrink);

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {}

    });
final Animation shrink=AnimationUtils.loadAnimation(活动,R.anim.shrink);
shrink.setFillAfter(true);
gallery.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
//这将遍历当前显示在屏幕上的视图。

对于(int k=0;k抱歉,我没有注意到,但我仍然找不到一种方法来放大和缩小imageswitcher本身中的图像…我的意思是可以看到的顶部…单击时,它应该会给我们一个正常大小,否则会缩小大小…我是否缺少一些琐碎的解决方案?我正在做同样的事情,但它在某些andro中不起作用id设备,如果您已经在gallery视图中实现了此动画,请发送代码给我。+1未看到此内容。接受作为答案。感谢您的时间伙计们!非常有用。
private class SelectListener implements AdapterView.OnItemSelectedListener {
     private Animation grow;
     private int last;

     public SelectListener() {
        grow = AnimationUtils.loadAnimation(RouteGallery.this, R.anim.grow);
        last = 0;
     }

     public void  onItemSelected  (AdapterView<?>  parent, View  v, int position, long id) {
        View sideView = parent.findViewById(last);
        if (sideView != null && last != position)
           sideView.clearAnimation();

        v.startAnimation(grow);
        last = position;
     }

    public void  onNothingSelected  (AdapterView<?>  parent) {
    }
}
final Animation shrink = AnimationUtils.loadAnimation(activity, R.anim.shrink);
shrink.setFillAfter(true);

gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            // This iterates through the views which are currently displayed on screen.
            for (int k=0; k<gallery.getChildCount(); k++){
                // Do whatever else you want, here.
                // This is how you get a particular element of a view
                ImageView background = (ImageView) gallery.getChildAt(k).findViewById(R.id.menu_item_background);

                //clear animation
                gallery.getChildAt(k).clearAnimation();

            }

            // Scale the selected one
            view.startAnimation(shrink);

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {}

    });