java如何沿Y轴移动gif
我想知道如何沿着Y轴移动gif。我认为这类似于移动一个ImageView,但是,这不起作用。我只是在尝试将gif沿Y轴从页面顶部移动到页面底部。gif将在沿Y轴移动时播放。动画只需获取gif的alpha,并将其从0.0打开到1.0。并沿Y轴变换gif的位置。我不知道如何用ImageView管理它。我已经包括了页面的XML文件、动画的XML文件和页面翻译的Java文件
我的XML文件是:
<?xml version="1.0" encoding="utf-8"?>
<安卓x.constraintlayout.widget.ConstraintLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:orientation="vertical"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@drawable/splash_screen_bg"
tools:context=".MainActivity">
<pl.droidsonroids.gif.GifImageView
安卓:id="@+id/gifAudio"
安卓:layout_width="250dp"
安卓:layout_height="250dp"
安卓:src="@drawable/bass_speaker"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.095" />
<ImageView
安卓:id="@+id/applogo"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_marginStart="10dp"
安卓:layout_marginTop="160dp"
安卓:layout_marginEnd="10dp"
安卓:src="@drawable/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
安卓:id="@+id/presstitle"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_marginTop="74dp"
安卓:text="PRESS 1"
安卓:textAlignment="center"
安卓:textColor="#044070"
安卓:textSize="70sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/applogo" />
<TextView
安卓:id="@+id/pressactive"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:shadowColor="@color/black"
安卓:shadowDx="5"
安卓:shadowDy="5"
安卓:shadowRadius="1"
安卓:text="Now Active"
安卓:textAlignment="center"
安卓:textColor="#6C6C6C"
安卓:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/presstitle" />
</安卓x.constraintlayout.widget.ConstraintLayout>
我的Java文件是:
package com.quadsoftentertainment.press1;
import 安卓x.appcompat.app.AppCompatActivity;
import 安卓.content.Intent;
import 安卓.os.Bundle;
import 安卓.os.Handler;
import 安卓.view.WindowManager;
import 安卓.view.animation.Animation;
import 安卓.view.animation.AnimationUtils;
import 安卓.widget.ImageView;
import 安卓.widget.TextView;
import pl.droidsonroids.gif.GifImageView;
// ****** Main Activity is the SPLASH SCREEN for the Press 1 application ******
public class MainActivity extends AppCompatActivity {
//Delay time
private static int SPLASH_SCREEN = 5000;
//var
Animation topAnim, bottomAnim, bottomPulseAnim, backAnim;
ImageView logoImg;
TextView logoTxt, sloganTxt;
GifImageView backVid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
//Animations
topAnim = AnimationUtils.loadAnimation(this,R.anim.top_animation);
bottomAnim = AnimationUtils.loadAnimation(this,R.anim.bottom_animation);
bottomPulseAnim = AnimationUtils.loadAnimation(this, R.anim.bottom_pulse);
backAnim = AnimationUtils.loadAnimation(this, R.anim.back_animation);
//Hooks
backVid = findViewById(R.id.bass_speaker); // error on this line, cannot find id of gif
logoImg = findViewById(R.id.applogo);
logoTxt = findViewById(R.id.presstitle);
sloganTxt = findViewById(R.id.pressactive);
backVid.setAnimation(backAnim);
logoImg.setAnimation(topAnim);
logoTxt.setAnimation((bottomPulseAnim));
sloganTxt.setAnimation(bottomAnim);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent move = new Intent(MainActivity.this, MainProgram.class);
startActivity(move);
finish();
}
}, SPLASH_SCREEN);
}
}
我的动画XML文件是:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:安卓="http://schemas.安卓.com/apk/res/安卓">
<translate
安卓:fromXDelta="0%"
安卓:fromYDelta="-50%"
安卓:duration="2000"/>
<alpha
安卓:fromAlpha="0.1"
安卓:toAlpha="1.0"
安卓:duration="2000"/>
</set>
任何帮助都会很好。谢谢
共 (0) 个答案