我有動畫的一個問題,這裏是我的代碼:動畫在相對layour重新定位的Android其它視圖
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Animation anim= new TranslateAnimation(0, 0, 0, -200);
anim.setDuration(2000);
anim.setFillAfter(true);
findViewById(R.id.button1).startAnimation(anim);
}
}, 2000);
}
和主要佈局是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:text="Button"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:minHeight="120sp"/>
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:text="Button"
android:layout_height="fill_parent"
android:layout_below="@id/button1"
android:minHeight="120sp"/>
</RelativeLayout>
我想BUTTON2與按鈕1一起移動。我知道我可以將相同的動畫應用到兩個按鈕,並且它們一起移動,但是然後button2將移動到底部邊距。
有人知道我該如何解決它嗎?
感謝您的答案。所以,如果我想要按鈕2展開,直到填滿整個窗口,我應該結合翻譯和垂直縮放?然後把按鈕1去右? – Addev
使用你的代碼,如果你只是將button1設置爲GONE,button2擴展並填充整個佈局,因爲android:layout_height =「fill_parent」屬性。所以只需在動畫後將button1設置爲GONE即可。 –
是的,但我想動畫不需要的時刻翻譯按鈕1 – Addev