安卓:动画相册模式?模式、动画、相册

2023-09-05 06:54:37 作者:温柔刀下鬼

当我用的是画廊小部件,我怎么得到的图像说规模向上和发光的被选中,并缩小和放大器;对未选择的是未发光?所有我见过的教程有这种效果,但我不能看到它...有一些动画的,我必须附加到画廊?

When I use the Gallery widget, how do I get the images to say scale up & glow on being selected and scaled down & un-glow on being unselected? All the tutorials I've seen have this effect but I am not able to see it... Is there some kind of an animation that I have to attach to the Gallery?

推荐答案

希望这是有帮助的。我设法模拟与图库插件的收缩/成长的解决方案。由于他们去掉了中的getScale(),事情变得有点复杂。我认为这是不是最好的解决办法可言,但至少我可以接受它。

Hope this is helpful. I manage to "simulate" the shrink/grow solution with the Gallery widget. Since they removed the getScale(), things get a little bit complicated. I think that this it's not the best solution at all, but at least I can live with it.

我所发现的是,图库管理​​的焦点极其恶劣。因此,第一种方法是增加一个焦点变化监听器上的的ImageView 显示,但没有运气。福克斯是一个烂摊子那里...的术语,所选图像这不是目前的工作重点视图。我已经发了邮件给Android的开发者邮件列表中有关API文档的一些错误(关于 focusSearch()方法,有的侧重contants)。

What I have found is that Gallery manages the focus EXTREMELY BAD. So, the first approach was to add a focus change listener on the ImageView displayed, but no luck there. Focus is a MESS there... in terms that, the selected image it's not the currently focused view. I have sent a mail to android-developers mailing list about some error on API doc (regarding the focusSearch()method and some focus contants).

下面是我解决这个问题:

Here's my solution to this problem:

建立一个动画资源成长的形象:

Build an animation resource to 'grow' the image:

<?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"/>

如果你没有得到什么意思,那么你应该继续读this

If you don't get what that means then you should proceed to read this

这将是我们的'成长'的效果,你需要将它保存在: RES /动画/ grow.xml 或任何其命名为五星级,你(但总是在RES /阿尼姆目录)。

That will be our 'grow' effect, and you will need to save it in: res/anim/grow.xml or whatever name it suites you (but always in res/anim dir).

您可以遵循资源指南这里创建图库视图。该 ImageAdapter 生成一个的ImageView 每一次的图库对象电话 getView()。你可以实现一个解决方法是添加一行到 getView()方法标识查看位置,这种方式:

You can follow the resource guide from here to create a Gallery view. The ImageAdapter builds an ImageView every time that the Gallery object calls getView(). One workaround you could implement is adding a line to the getView() method that identifies a View with a position, this way:

...
i.setId(position);
...

使用该行添加到 ImageAdpater 对象的 getView()方法,你就可以明确识别查看监听器中,例如:

With that line added to the getView() method of the ImageAdpater object, you can then unequivocally identify that view within a listener, for instance:

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");

    }
    });

请注意:您可能会注意到,从动画和布局参数所有的值已在眼前choosen由我。这是因为我不打算清理code为您服务。而且,这仅仅是一个解决办法与这个小工具还是Android查看系统的BAD焦点问题。如果焦点都行,那么,所有你需要做的是设置一个焦点变化监听器,使得格罗斯/收缩时,它得到了集中/聚焦。

NOTE: You may notice that all the values from animation and from layout parameters has been choosen by me at hand. This is because i'm not going to clean code for you. And, this is just a workaround the BAD focus issue with this widget or the android view system. If focus were OK, then, all you need to do is set a focus change listener that makes the gros/shrink when it got focus/unfocused.

我希望这可以帮助你发现身边为你的问题的方法,

I hope this may help you to find a way around for your problem,

问候,

新的编辑:这是我设置的听众,我还增加了行 i.clearAnimation() getView()方法:

New This is the listener I have set, I also added the line i.clearAnimation() in the getView() method:

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) {
    }
}