Android Imitation Order Ticketing effect (demo included)

Source: Internet
Author: User

Before I downloaded the baseanimation Open Source Library (Baseanimation is an open source app, dedicated to collecting various animation effects)

Baseanimation Reprinted Links: http://blog.csdn.net/vipzjyno1/article/details/20622621

Found inside there is a fire ticket ticket effect, found that can be optimized under:

Effect of baseanimation in the inside of a ticket

But it's out of the ticket layout height of what is written dead, through this idea, I think to do a similar to the data is obtained through the network, the height is not necessarily the ListView order ticket effect.

A. Ideas:

1) stacked on the top of the layout is the order information, and on the lower level is the order of the menu in detail, the layout of the detailed items is placed at the bottom of the layout, and in the relative position of the order information, where the framelayout to handle the detailed layout of the item.

2) The list of detailed entries for the ticket is taken by the ListView, and its initial position is calculated by calculating the total height of the ListView, after which the animation animation is performed by Translateanimation.

3) using a thread to simulate the network to obtain the effect of delay.

Two. Problems solved:

1) Encounter a problem, that is, if the data more than a screen, animation in the process of cohesion is very poor, and there may be a fault effect.

Workaround: This solves the problem by overriding the ListView, calculating the height, and nesting a layer of scrollview outside the ListView.

2) If a ListView is placed directly below the order information layout, then the ListView will cover the order information when the animation is animated.

Solution: The listview layer must be nested in a layout, and set under the order information, so that does not produce the above problem.

3) due to the bottom of the order

It starts out, and slides along with the ListView after the data is refreshed.

Workaround: Use the Addfooterview (bottom view) method of the ListView to add it to the bottom of the ListView and initialize the Listview.setadapter (NULL) directly after the start of the Add.

This will be displayed at the beginning of the bottom.

4) How to calculate the total height of the ListView

Solution: This demo uses 2 different ways,

First: Given that the layout of each item in the order is fixed, the height of the item in the layout is fixed and then multiplied by Listadapter.getcount () plus the total height of the split line Listview.getdividerheight ()

Second: If the layout of each item is not necessarily the height, it will affect, then found some information, using the following methods:

[Java]View Plaincopyprint?
  1. /** ListView Total Height */
  2. Public static int totalheight = 0;
  3. Public static void Setlistviewheightbasedonchildren (ListView listview) {
  4. ListAdapter listadapter = Listview.getadapter ();
  5. if (listadapter = = null) {
  6. return;
  7. }
  8. Totalheight = 0;
  9. //Because add a footer, so the total minus 1
  10. LOG.D ("Listadapter.getcount ()", " " "+ Listadapter.getcount ());
  11. for (int i = 0, len = Listadapter.getcount ()- 1; i < Len; i++) {
  12. View ListItem = Listadapter.getview (i, null, ListView);
  13. Listitem.measure (0, 0);
  14. Totalheight + = Listitem.getmeasuredheight ();
  15. LOG.D ("Getmeasuredheight", " " "+ listitem.getmeasuredheight ());
  16. }
  17. Totalheight = Totalheight + (listview.getdividerheight () * (Listadapter.getcount ()- 1));
  18. }
/** ListView Total Height */public static int totalheight = 0;public static void Setlistviewheightbasedonchildren (ListView listview {ListAdapter listadapter = Listview.getadapter (); if (listadapter = = null) {return;}  Totalheight = 0;//Because add a footer, so the total minus 1log.d ("Listadapter.getcount ()", "" "+ Listadapter.getcount ()); for (int i = 0, Len = Listadapter.getcount ()-1; i < Len; i++) {View ListItem = Listadapter.getview (i, NULL, ListView); listitem.measure (0, 0); Totalheight + = Listitem.getmeasuredheight (); LOG.D ("Getmeasuredheight", "" "+ Listitem.getmeasuredheight ());} Totalheight = Totalheight + (listview.getdividerheight () * (Listadapter.getcount ()-1));}


The total height of the calculation is obtained.

5) Achieve animation effect

Solve:

[Java]View Plaincopyprint?
  1. /** 
  2. * Start the print order animation
  3. */
  4. Rivate void Startanimation () {
  5. Anim = new Translateanimation (0.0f, 0.0f,-totalheight, 0);
  6. Anim.setduration (1000);
  7. Anim.setfillafter (true);
  8. Anim.setanimationlistener (new Animationlistener () {
  9. @Override
  10. public void Onanimationstart (Animation Animation) {
  11. //TODO auto-generated method stub
  12. }
  13. @Override
  14. public void Onanimationrepeat (Animation Animation) {
  15. //TODO auto-generated method stub
  16. }
  17. @Override
  18. public void Onanimationend (Animation Animation) {
  19. //TODO auto-generated method stub
  20. Clistview.clearanimation ();
  21. }
  22. });
  23. Clistview.startanimation (ANIM);
        /** * Start print order animation */private void Startanimation () {anim = new translateanimation (0.0f, 0.0f,-totalheight, 0); anim.setduratio n (+); Anim.setfillafter (true); Anim.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {//TODO auto-generated method stub} @Overridepublic void Onanimationrepeat ( Animation Animation) {//TODO auto-generated method stub} @Overridepublic void Onanimationend (Animation Animation) {//TOD O auto-generated Method Stubclistview.clearanimation ();}}); Clistview.startanimation (ANIM);}

Finally, take a look at the animation effect:

Because it is the first time to write a blog, there is a lack of hope that the great God put forward their views and suggestions and common progress. Thank you!

Reprint Please attach: http://blog.csdn.net/vipzjyno1/article/details/20623401

Demo Source Download Link:

http://download.csdn.net/detail/vipzjyno1/7000355

(turn) Android imitation Order ticketing effect (with demo)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.