android典型程式碼系列(二十二)------按鍵使上面的EditText抖動

fandong12388發表於2015-12-06

這裡寫圖片描述
按鍵使上面的EditText抖動:
1. query_number.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <EditText android:layout_width="fill_parent"
        android:layout_marginTop="5dip"
        android:layout_height="wrap_content"
        android:id="@+id/et_NumberQueryActivity"
        android:hint="請輸入要查詢的手機號碼"/>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/bt_NumberQueryActivity"
        android:text="查詢"/>
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv_NumberQueryActivity"/>
</LinearLayout>

2. res- anim– et_numberqueryactivity.xml

<?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"></translate>

3. res-anim-cycle_7.xml

 <?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
        android:cycles="7"></cycleInterpolator>

4. NumberQueryActivity.java

public class NumberQueryActivity extends Activity implements 
OnClickListener {
    private static final String TAG = "NumberQueryActivity";
    private EditText et;
    private TextView tv;
    private Button bt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.query_number);
        et=(EditText) this.findViewById(R.id.et_NumberQueryActivity);
        bt=(Button) this.findViewById(R.id.bt_NumberQueryActivity);
        tv=(TextView) this.findViewById(R.id.tv_NumberQueryActivity);
        bt.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        String et_content=et.getText().toString().trim();
        if(TextUtils.isEmpty(et_content)){
            Animation animation = AnimationUtils.loadAnimation(this, 
R.anim.et_numberqueryactivity);
            et.startAnimation(animation);
            return;
        }else{
            Logger.i(TAG, "開始查詢");
        }
    }
}

相關文章