我嘗試將按鈕從頂部移動到屏幕上的固定位置,當clicklistener添加到按鈕上時它工作正常,但在連接到相關佈局時它不起作用。這樣包含relativelayout的按鈕就會變成動畫。我認爲問題是在嵌套視圖組中添加布局時,請幫助我解決問題。提前致謝。附加到父級(RelativeLayout)佈局時動畫不起作用?
b = (Button) findViewById(R.id.simpleButton);
relativeLayout = (RelativeLayout) findViewById(R.id.wrapper);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
b.startAnimation(animations());
}
});
relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
relativeLayout.setAnimation(animations());
}
});
}
private TranslateAnimation animations() {
TranslateAnimation translateAnimation = new TranslateAnimation(0f, 0f, 0, -40);
translateAnimation.setDuration(1000);
translateAnimation.setInterpolator(new AccelerateInterpolator());
return translateAnimation;
}
這裏是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">
<RelativeLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:background="#cbcbbc"
android:layout_height="60dp">
<Button
android:id="@+id/simpleButton"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Go next page" />
</RelativeLayout>
</LinearLayout>
帖子'xml'佈局。 – azizbekian
你想要實現什麼? – azizbekian
當我按下按鈕時,佈局從頂部進入並進入其位置,同樣我想用包括父佈局在內的整個佈局實現該佈局。它僅適用於按鈕點擊,而不是相對佈局點擊 –