0
我正在Android Studio工作,我試圖在應用程序啓動後立即將屏幕上的按鈕設置爲屏幕上的某個位置(沒有任何點擊)。有誰知道一種方法來做到這一點?我對Android工作室相當陌生,所以我對基礎知識很熟悉,但沒有比這更多,謝謝你。在Android Studio中設置動畫/移動按鈕
我正在Android Studio工作,我試圖在應用程序啓動後立即將屏幕上的按鈕設置爲屏幕上的某個位置(沒有任何點擊)。有誰知道一種方法來做到這一點?我對Android工作室相當陌生,所以我對基礎知識很熟悉,但沒有比這更多,謝謝你。在Android Studio中設置動畫/移動按鈕
它可能給你一個線索:
RelativeLayout rl = new RelativeLayout(this);
LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rl.setLayoutParams(params);
Button button = new Button(this);
button.setText("AABBBCCC");
LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
button.setLayoutParams(params1);
rl.addView(button);
您可以使用翻譯的動畫吧。首先在/res/anim/anim_translate.xml
文件夾中創建這個XML動畫文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500"
android:repeatCount="1"
android:repeatMode="reverse"/>
</set>
然後將其設置爲您的按鈕:
final Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
yourButton.startAnimation(animTranslate);
您可以根據您的需要進行修改。
更具體地說,我試圖將按鈕從屏幕底部移動到屏幕居中1/4左右的位置。 – cnthomas8