Android instance-one of the personal financial management tools startup interface implementation

Source: Internet
Author: User
Go to restart.

Interface effect:

The interface is very simple. How does one imageview and one textview vertically center two views? I cannot center vertically or horizontally using linearlayout. later, we used relativelayout to solve the problem of horizontal center. the specific XML of the interface is as follows: Main. XML
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Relativelayout Android: Id = "@ + ID/relativelayout01" xmlns: Android = "http://schemas.android.com/apk/res/android"
  3. Android: layout_gravity = "center_vertical | center_horizontal"
  4. Android: layout_height = "wrap_content"
  5. Android: layout_width = "wrap_content">
  6. <Imageview Android: Id = "@ + ID/imageview01"
  7. Android: src = "@ drawable/logo3"
  8. Android: layout_width = "wrap_content"
  9. Android: layout_height = "wrap_content">
  10. </Imageview>
  11. <Textview Android: Id = "@ + ID/textview01"
  12. Android: text = "@ string/welcome"
  13. Android: layout_below = "@ ID/imageview01"
  14. Android: layout_width = "wrap_content"
  15. Android: layout_height = "wrap_content">
  16. </Textview>
  17. </Relativelayout>

Here, I will use a tips: after the program Initialization is complete, let the image fade out and then display the next interface.

At first, I plan to use a timer to update the image's Alpha value. Later, the program throws an exception only the original thread that created a view hierarchy can touch its views. only then can we find that the android UI control is thread-safe. here we need to open another thread to update the image on the Interface outside the main thread. you can use imageview. the code for invalidate on how to open another thread update interface is as follows.
  1. // Send a message to the main thread to update the imageview
  2. Mhandler = new handler (){
  3. @ Override
  4. Public void handlemessage (Message MSG ){
  5. Super. handlemessage (MSG );
  6. Imageview. setalpha (alpha );
  7. Imageview. invalidate ();
  8. }
  9. };
  10. New thread (New runnable (){
  11. Public void run (){
  12. While (B <2 ){
  13. Try {
  14. // The imageview is updated every 50 milliseconds after a delay of 2 seconds
  15. If (B = 0 ){
  16. Thread. Sleep (2000 );
  17. B = 1;
  18. } Else {
  19. Thread. Sleep (50 );
  20. }
  21. Updateapp ();
  22. } Catch (interruptedexception e ){
  23. E. printstacktrace ();
  24. }
  25. }
  26. }
  27. }). Start ();
  28. Public void updateapp (){
  29. Alpha-= 5; // reduce alpha 5 each time
  30. If (alpha <= 0 ){
  31. B = 2;
  32. Intent in = new intent (this, Com. Cola. UI. frm_addbills.class );
  33. Startactivity (in); // start the next interface
  34. }
  35. Mhandler. sendmessage (mhandler. obtainmessage ());
  36. }

 

Through this code, we can understand how to update the UI view in Android.

In the next article, let's take a look at the usage of SQLite and how to initialize the program.

About handler and invalidate usage,

You can also refer to this Article. http://www.blogjava.net/gooogle/archive/2008/03/05/184030.html

 

Colabox. Java:
  1. Package com. Cola. UI;
  2. Import Android. App. activity;
  3. Import Android. content. intent;
  4. Import Android. OS. Bundle;
  5. Import Android. OS. Handler;
  6. Import Android. OS. message;
  7. Import Android. util. log;
  8. Import Android. View. keyevent;
  9. Import Android. widget. imageview;
  10. Import Android. widget. textview;
  11. Public class colabox extends activity {
  12. Private handler mhandler = new handler ();
  13. Imageview;
  14. Textview;
  15. Int alpha = 255;
  16. Int B = 0;
  17. Public void oncreate (bundle savedinstancestate ){
  18. Super. oncreate (savedinstancestate );
  19. Setcontentview (R. layout. Main );
  20. Imageview = (imageview) This. findviewbyid (R. Id. imageview01 );
  21. Textview = (textview) This. findviewbyid (R. Id. textview01 );
  22. Log. V ("colabox", "colabox start ...");
  23. Imageview. setalpha (alpha );
  24. New thread (New runnable (){
  25. Public void run (){
  26. Initapp (); // initialization program
  27. While (B <2 ){
  28. Try {
  29. If (B = 0 ){
  30. Thread. Sleep (2000 );
  31. B = 1;
  32. } Else {
  33. Thread. Sleep (50 );
  34. }
  35. Updateapp ();
  36. } Catch (interruptedexception e ){
  37. E. printstacktrace ();
  38. }
  39. }
  40. }
  41. }). Start ();
  42. Mhandler = new handler (){
  43. @ Override
  44. Public void handlemessage (Message MSG ){
  45. Super. handlemessage (MSG );
  46. Imageview. setalpha (alpha );
  47. Imageview. invalidate ();
  48. }
  49. };
  50. }
  51. Public void updateapp (){
  52. Alpha-= 5;
  53. If (alpha <= 0 ){
  54. B = 2;
  55. Intent in = new intent (this, Com. Cola. UI. frm_addbills.class );
  56. Startactivity (in );
  57. }
  58. Mhandler. sendmessage (mhandler. obtainmessage ());
  59. }
  60. Public void initapp (){
  61. }
  62. }
Related Article

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.