2013-03-28 39 views
0

我做了一個簡單的按鈕移動動畫。但是當我完成按鈕翻譯動畫後,按鈕焦點不會隨着按鈕移動。焦點仍然停留在原來的位置。如何使焦點與按鈕一起移動?

如何使焦點與按鈕移動?我的SDK API級別爲15

的代碼是這樣的:

package com.example.test; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.Button; 

public class MainActivity extends Activity { 

    private Button mButton; 

    private Animation mButtonAnimation; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     mButton = (Button) findViewById(R.id.button1); 
     mButton.setOnClickListener(new Button.OnClickListener() { 
      public void onClick(View v) { 
       mButtonAnimation.setFillAfter(true); 
       mButton.startAnimation(mButtonAnimation); 
      } 
     }); 

     mButtonAnimation = AnimationUtils.loadAnimation(this, R.anim.button_anim); 
    } 
} 

佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <Button 
     android:id="@+id/button1" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="Button" /> 

</RelativeLayout> 

button_anim.xml:

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

    <translate 
     android:duration="500" 
     android:fromYDelta="0" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:toYDelta="100" /> 
</set> 

回答

0

嘗試fillAfter = true,看到sdk