我正在android studio上工作。我先告诉你我需要什么作为输出。有2个屏幕。在第一个中,我放置了一个图像。我想要的是,无论何时启动或打开该应用程序,主屏幕中的图像都会淡入几秒钟,然后自动移至第二个屏幕。没有任何按钮,没有任何点击监听器。我看到了一些教程,尽管我设法通过单击侦听器来做到这一点。现在我希望它自动淡入几秒钟,然后出现几秒钟的屏幕。以下是主屏幕的代码。
Java代码:
public class MainActivity extends AppCompatActivity {
private static int SPLASH_TIME = 4000; //This is 4 seconds
private ImageView object;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
object=(ImageView)findViewById(R.id.fadein);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent mySuperIntent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(mySuperIntent);
finish();
}
}, SPLASH_TIME);
}
public void onFade(View view) {
Animation FadeAnim= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.view_fade);
object.startAnimation(FadeAnim);
}
}
该xml文件仅包含图像属性和一个onclick。
答案 0 :(得分:0)
您可以添加一个侦听器并在其上启动下一个活动
using UnityEngine;
public class KeyboardMovement : MonoBehaviour
{
private CharacterController controller;
public float walkSpeed;
public float sprintSpeed;
public float crouchSpeed;
public float jumpHeight;
Vector3 up = Vector3.zero;
Vector3 movement = Vector3.zero;
Vector3 forward = Vector3.zero;
Vector3 sideways = Vector3.zero;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
float speed = walkSpeed;
//If crouching, set speed to crouch speed. This ovverides sprinting
if (SingletonSettings.GetKey(SingletonSettings.Keybindings.crouch))
speed = crouchSpeed;
//Else if sprinting, set speed to sprint speed
else if (SingletonSettings.GetKey(SingletonSettings.Keybindings.sprint))
speed = sprintSpeed;
//Create vectors for movement
forward = transform.TransformDirection(Vector3.forward) * Input.GetAxis("Vertical");
sideways = transform.TransformDirection(Vector3.right) * Input.GetAxis("Horizontal");
//up = SingletonSettings.GetKey(SingletonSettings.Keybindings.jump) && controller.isGrounded ? Vector3.up * jumpHeight : Vector3.zero;
movement = (up * 100) + ((forward + sideways) * 10 * Time.deltaTime * speed);
//Combine vectors and Multiply by DeltaTime to ensure smooth movement at different framerates.
//Also multiply by 10*speed to ensure correct speed in different states
if (controller.isGrounded && Input.GetKey(KeyCode.Space))
{
movement.y = jumpHeight*50 * Time.deltaTime;
}
controller.SimpleMove(movement);
}
void OnGUI()
{
GUILayout.Label('\n' + Newtonsoft.Json.JsonConvert.SerializeObject(movement.y, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
}));
}
}
答案 1 :(得分:0)
您只需要做的就是从imgView中删除onClick函数,并在public void run()之前在onCreate函数中实现动画代码行。让我知道它是否对您有用