XML code
- Add a imageviw and a edittext to the layout.
XML code
- <ImageView
- android:id="@+id/loading_imageview_info"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:background="@anim/loading" />
- <EditText
- android:id="@+id/loading_edittext_info"
- android:layout_width="0DP"
- android:layout_height="0DP" />
Java code
- <pre class="java" name="code" > private ImageView loadingimageview;
- private EditText Loadingedittext;
- Private animationdrawable anim;</pre>
Java code
- Loadingimageview = (ImageView) Findviewbyid (r.id.loading_imageview_info);
- Loadingedittext = (EditText) Findviewbyid (r.id.loading_edittext_info);
- Loadingedittext.setinputtype (Inputtype.type_null); //Shielded soft keyboard
- Anim = (animationdrawable) loadingimageview.getbackground ();
- Loadingedittext.setonfocuschangelistener (Editsetonfocus);
Java code
- /**
- * When the input box gets focus, the animation is run
- */
- private Onfocuschangelistener Editsetonfocus = new Onfocuschangelistener () {
- @Override
- public void Onfocuschange (View V, boolean hasfocus) {
- //TODO auto-generated method stub
- Anim.start ();
- LOG.I ("text", "execution wait Animation .....") ");
- }
- };
When the program gets to the data the general situation is to send a message in Hanlder to notify the animation to stop and hide the current control
Java code
- Anim.stop ();
- Loadingimageview.setvisibility (View.gone);
The Anim animation is defined in XML with the following code:
Java code
- <?xml version="1.0" encoding="UTF-8"?>
- <animation-list android:oneshot="false" xmlns:android="Http://schemas.android.com/apk/res/android" >
- <item android:duration= "android:drawable="@drawable/load1 "/>
- <item android:duration= "android:drawable="@drawable/load2 "/>
- <item android:duration= "android:drawable="@drawable/load3 "/>
- <item android:duration= "android:drawable="@drawable/load4 "/>
- <item android:duration= "android:drawable="@drawable/load5 "/>
- <item android:duration= "android:drawable="@drawable/load6 "/>
- </animation-list>
Android image loading in wait for animation