Application of Animation on Activity Login

Source: Internet
Author: User

If an account logon error is displayed in the pop-up box, it will be ugly and unfriendly. Of course, Toast is also a good choice. Here we provide an Animation effect of Animation to indicate an input error. When the user name or password is incorrect, the input box will shake left and right to indicate "incorrect user name or password ". At the same time, we will use this small case to get a preliminary understanding of the Animation. Create an anim folder in the res directory of the project to store the XML of the Animation. Create shake. xml as follows: [java] <? Xml version = "1.0" encoding = "UTF-8"?> <Translate xmlns: android = "http://schemas.android.com/apk/res/android" android: fromXDelta = "0" android: toXDelta = "10" android: duration = "1000" android: interpolator = "@ anim/cycle_7"/> fromXDelta indicates the position of the control in the horizontal direction when the animation starts. toXDelta indicates the displacement pixel in the horizontal direction. Correspondingly, fromYDelta and toYDelta can also be used. Duration indicates the animation duration. Animation application [java] Animation shake = AnimationUtils. loadAnimation (this, R. anim. shake); findViewById (R. id. editText2 ). startAnimation (shake); findViewById (R. id. editText1 ). startAnimation (shake); full application of Java file [java] package com. app; import android. annotation. suppressLint; import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. view; Import android. view. animation. animation; import android. view. animation. animationUtils; import android. widget. editText; import android. widget. toast; @ SuppressLint ("NewApi") public class MyQQActivity extends Activity implements View. onClickListener {/** Called when the activity is first created. * // @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setCo NtentView (R. layout. qq_login); findViewById (R. id. button1 ). setOnClickListener (this); findViewById (R. id. button2 ). setOnClickListener (this); findViewById (R. id. button3 ). setOnClickListener (this);} public void onClick (View v) {EditText editText1 = (EditText) findViewById (R. id. editText1); String text1 = editText1.getText (). toString (); EditText editText2 = (EditText) findViewById (R. id. editText2); String t Ext2 = editText2.getText (). toString (); switch (v. getId () {case R. id. button1: if (text1.equals (text2) {Intent intent2 = new Intent (); intent2.setClass (MyQQActivity. this, Tabs. class); startActivity (intent2); int version = Integer. valueOf (android. OS. build. VERSION. SDK); if (version> = 5) {overridePendingTransition (R. anim. zoomin, R. anim. zoomout) ;}} else {Toast. makeText (MyQQActivity. this, "the account or password is incorrect. Incorrect. enter a new one! ", Toast. LENGTH_LONG ). show (); Animation shake = AnimationUtils. loadAnimation (this, R. anim. shake); findViewById (R. id. editText2 ). startAnimation (shake); findViewById (R. id. editText1 ). startAnimation (shake); editText2.setText (null);} break; case R. id. button2: // register the account Uri uri1 = Uri. parse ("http://zc.qq.com/chs/index.html"); Intent it1 = new Intent (Intent. ACTION_VIEW, uri1); startActivity (it1); break; case R. id. button3: // Uri uri2 = Uri. parse ("https://aq.qq.com/cn2/findpsw/pc/pc_find_pwd_input_account"); Intent it2 = new Intent (Intent. ACTION_VIEW, uri2); startActivity (it2); break; default: break ;}} layout file [java] <? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/qqlogin" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical" android: background = "@ drawable/phone_call_bg" android: padding = "10dp"> <LinearLayout android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: orientation = "vertical"> <ImageVie W android: id = "@ + id/imageView1" android: layout_width = "fill_parent" android: layout_height = "120dp" android: layout_marginTop = "15dp" android: src = "@ drawable/ic_launcher"/> </LinearLayout> <RelativeLayout android: layout_width = "match_parent" android: layout_height = "100dp" android: layout_marginTop = "15dp" android: background = "@ drawable/login_management_background" android: padding = "10dp"> <TextView android: I D = "@ + id/textView1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentLeft = "true" android: layout_alignParentTop = "true" android: layout_marginLeft = "15dp" android: layout_marginTop = "10dp" android: layout_marginBottom = "5dp" android: text = "Account" android: textSize = "20dp" android: textColor = "#333"/> <TextView android: id = "@ + id/textView2" android: layout_width = "wrap _ Content "android: layout_height =" wrap_content "android: layout_alignParentLeft =" true "android: layout_below =" @ + id/textView1 "android: layout_alignLeft =" @ + id/textView1 "android: layout_marginLeft = "15dp" android: layout_marginTop = "5dp" android: layout_marginBottom = "10dp" android: text = "password" android: textSize = "20dp" android: textColor = "#333"/> <EditText android: id = "@ + id/editText1" android: layout_width = "wrap_con Tent "android: layout_height =" wrap_content "android: paddingTop =" 3dp "android: layout_alignBaseline =" @ + id/textView1 "android: layout_alignBottom =" @ + id/textView1 "android: layout_marginLeft = "22dp" android: drawableTop = "# fff" android: hint = "username/email" android: phoneNumber = "true" android: layout_toRightOf = "@ + id/textView1" android: EMS = "10"> <requestFocus/> </EditText> <EditText android: id = "@ + id/editText2" andro Id: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignBaseline = "@ + id/textView2" android: layout_alignBottom = "@ + id/textView2" android: layout_alignLeft = "@ + id/editText1" android: EMS = "10" android: phoneNumber = "true" android: drawableTop = "# fff" android: hint = "enter the password" android: inputType = "textPassword"/> </RelativeLayout> <LinearLayout android: layout_width = "wrap_content" android Oid: layout_marginTop = "15dp" android: layout_height = "40dp" android: orientation = "horizontal"> <Button android: id = "@ + id/button1" android: layout_width = "170dp" android: layout_height = "40dp" android: layout_marginLeft = "60dp" android: background = "@ drawable/bg_alibuybutton" android: text = "login" android: gravity = "center" android: textSize = "20sp" android: textColor = "#000000"/> </LinearLayout> <LinearLayout android: Layout_width = "fill_parent" android: layout_marginTop = "100dp" android: gravity = "center_horizontal" android: orientation = "horizontal" android: layout_height = "wrap_content"> <Button android: id = "@ + id/button2" style = "? Android: attr/buttonStyleSmall "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: textSize =" 10sp "android: text = "register account"/> <Button android: id = "@ + id/button3" style = "? Android: attr/buttonStyleSmall "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: textSize =" 10sp "android: text = "forgot password"/> </LinearLayout>

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.