views:

31

answers:

2

Hi,

Inside of a ListView row, I have a box (right now its an imageview, but i will probably be converting it to a linear or relative layout object at some point). when you click on the box, i have it start a scale animation that makes it appear to grow. however, once the animation is over, the box goes immediately back to its original state. I'd like to have the box stay at the transformed size (at least until they click it again).

here's the xml:

<scale
    android:fromXScale="1" android:toXScale="5"
    android:fromYScale="1" android:toYScale="1"
    android:pivotX="100%" android:pivotY="0%" android:fillAfter="true"
    android:duration="600" />

A: 

well i got it to work...sorta. If i do it all in code and call setFillAfter, setFillBefore & setFillEnabled all = true, then it seems to work. the only problem, is that the outline on my box (its got a background drawable w/ a <stroke> element. the padding also seems to grow, i'd like to have that not grow...

Ben
A: 

the only way i was able to do this was by changing the width of the box on a new thread every 1ms. not pretty but it seemed to be the only way to maintain the borders of the box. if you come up w/ an option that uses the animation f/w please do let me know...

here's the code Rohan, don't forget to give me an up vote :)

    private void toggleMenu(final ViewHolder menu, final boolean doExpand) {
    final LayoutParams params = menu.actionMenu.getLayoutParams();
    final int originalWidth = params.width;

    Thread t = new Thread() {
        @Override
        public void run() {
            for (int i = 0; i < 200; i++) {
                if (doExpand) {
                    params.width = originalWidth + i;
                } else {
                    params.width = originalWidth - i;
                }
                menu.actionMenu.post(new Runnable() {

                    @Override
                    public void run() {
                        menu.actionMenu.requestLayout();

                    }
                });
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            menu.expandCollapseButton.post(new Runnable() {
                @Override
                public void run() {
                    if (doExpand) {
                        menu.expandCollapseButton
                                .setImageResource(R.drawable.monotone_arrow_right);
                    } else {
                        menu.expandCollapseButton
                                .setImageResource(R.drawable.monotone_arrow_leftpng);
                    }

                }
            });

            // menu.isExpanded = !menu.isExpanded;
        }
    };
    t.start();
}
Ben
@Ben:Can you please provide the code snippet of how you implemented it. i mean the entire class if you have done it programatically. I too want to implement the same thing and is stuck in between.
Rohan K