我有我的活動按鈕,使用TranslateAnimation改變其位置正確的結果。
我使用anim.setFillAfter(真);爲了保留最終的翻譯結果,按鈕會改變其位置,但觸摸區域保持不變。
現在,當我觸摸按鈕它不接觸,而在按鈕的前一個位置的工作要求其聽衆..
翻譯鈕釦不給
這裏是我的代碼:
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Animation anim=new TranslateAnimation(0, 100, 0, 0);
anim.setDuration(500);
anim.setFillAfter(true);
Button mybtn = (Button)findViewById(R.id.btn);
mybtn.startAnimation(anim);
}
public void myFunc(View v){
Toast.makeText(this, "btn clicked", Toast.LENGTH_SHORT).show();
}
}
activity_main.xml中
<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"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
android:onClick="myFunc"/>
</RelativeLayout>
你能嘗試刪除動畫和嘗試? – lokoko
我想要按鈕動畫到其他位置,並在那裏執行其點擊屬性。 –