Vibration of View in android

When doing app registration, the product requires the view to vibrate when the user name or password is entered incorrectly or not entered to remind the user. Here you can use animation to achieve the effect.

First, write the [xml] layout file:
this interface is not complicated:

<LinearLayout android:id="@+id/linear1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <EditText android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="50dp"
            android:background="@drawable/tab_ws_white_bg"
            android:inputType="phone"/>
        <EditText android:id="@+id/et_pwd"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/tab_ws_white_bg"
             android:inputType="textPassword"
            />
        <EditText android:id="@+id/et_okpwd"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="15dp"
             android:inputType="textPassword"
            android:background="@drawable/tab_ws_white_bg"/>
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginTop="10dp"
             android:layout_marginLeft="20dp"
             android:layout_marginRight="20dp">
            <TextView android:id="@+id/tv_error"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/red"
                android:gravity="center"
                />
        </LinearLayout>
        <Button android:id="@+id/bt_bind"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="80dp"
            android:layout_marginRight="80dp"
            android:layout_marginTop="20dp"
            android:textColor="#FFF"
            android:background="@drawable/bt_selector"/>

Then look at our code:
find our control, load our vibration animation, and set a listener for the Button.

Main code here: (view.startAnimation(shake))
et_pwd.startAnimation(shake);
et_okpwd.startAnimation(shake);

animation xml:

In fact, the code is very simple,………………Really simple………………..
Might as well code, if you need it, I will 1563277640. .

Leave a Comment

Your email address will not be published. Required fields are marked *