简体   繁体   English

除非通过第二个Java活动向后提示,否则我在第一个Java活动中的动画无法正常工作

[英]My animation in my 1st Java Activity doesn't work unless prompted backwards via the 2nd Java Activity

My 1st Activity java file source code is not working the way I want. 我的第一个Activity Java文件源代码无法按我想要的方式工作。 I can not seem to get the animation to run at the start of my 1st activity. 我似乎无法让动画在我的第一个活动开始时运行。 I can only get it to run after the 2nd Java Activity by physically going back to the 1st activity by hard pressing back on the Android keyboard. 我只能通过在Android键盘上用力按一下来实际返回第一个活动,从而使其在第二个Java活动之后运行。

package com.demotxt.droidsrce.welcomescreen;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;

public class WelcomeActivity extends AppCompatActivity {
    LinearLayout l1, l2;
    Button btnsub;
    Animation uptodown, downtoup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        btnsub = (Button) findViewById(R.id.buttonsub);
        btnsub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NextActivity();
            }
        });
    }

    public void NextActivity() {
        Intent intent = new Intent(this, NextActivity.class);
        startActivity(intent);
        l1 = (LinearLayout) findViewById(R.id.l1);
        l2 = (LinearLayout) findViewById(R.id.l2);
        uptodown = AnimationUtils.loadAnimation(this, R.anim.uptodown);
        downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
        l1.setAnimation(uptodown);
        l2.setAnimation(downtoup);
    }
}

This is my XML File for the 1st Activity and everything here is also running smoothly, but I have the same problem. 这是我的第一个活动的XML文件,这里的所有内容也运行顺利,但是我遇到了同样的问题。 There seems to be an issue running the java and XML script backward and forward to run the animation both ways. 前后运行Java和XML脚本以同时运行动画似乎存在问题。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.demotxt.droidsrce.welcomescreen.WelcomeActivity"
    android:orientation="vertical"
    android:background="@drawable/background">

    <LinearLayout
        android:id="@+id/l1"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="25dp"
            android:text="Welcome to"
            android:textColor="@color/lightorange"
            android:textSize="30sp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="398dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="50dp"
            android:text="           BLUEY AUSTRALIA"
            android:textAlignment="textStart"
            android:textColor="@android:color/holo_blue_light"
            android:textColorHighlight="@android:color/holo_blue_bright"
            android:textColorHint="@android:color/holo_blue_bright"
            android:textColorLink="@android:color/holo_blue_bright"
            android:textSize="30sp" />

        <ImageView
            android:id="@+id/Bluey_logo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/bluey_logo" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/l2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:background="@drawable/spaceullustration"
        android:orientation="vertical">

        <Button

            android:id="@+id/buttonsub"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/buttonstyle"
            android:text="JOIN BLUEY"
            android:textColor="@color/bluey"
            android:textSize="30sp" />
    </LinearLayout>


</LinearLayout>

try change the order 尝试更改订单

    l1 = (LinearLayout) findViewById(R.id.l1);
    l2 = (LinearLayout) findViewById(R.id.l2);
    uptodown = AnimationUtils.loadAnimation(this, R.anim.uptodown);
    downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
    l1.setAnimation(uptodown);
    l2.setAnimation(downtoup);
    startActivity(intent); //<<<<<<<<<<<<<<,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从第一个活动拨打电话后,第二个活动没有通话 - 2nd Activity doesn't call after calling from 1st Activity 如何从第二活动到第一活动获取数据 - How to get data from 2nd Activity to 1st Activity 从Android中的第一个应用程序开始第二个应用程序的活动 - Start Activity of 2nd app from 1st app in android 当我返回到第一个活动时,第二个活动未调用第二个活动的onCreate()函数 - When I return back to 1st Activity the onCreate() function of 2nd Activity is not called in 2nd time Java继承:第2个实例调用第1个实例方法 - Java Inheritance : 2nd instance calls 1st instance method Java多线程第二线程等待第一 - Java multithreading 2nd thread waiting for 1st 在 Java 中的字符串中查找第 1 次和第 2 次出现的正则表达式 - Finding the 1st and 2nd occurrence of a regex in a string in Java 在 java 中将第一个数组值乘以 1,将第二个值乘以 3 - Multiply 1st array value with 1 and 2nd value with 3 in java 无法通过getIntent()将第一个活动的textview值传递给第二个活动的textview - Unable to pass 1st activity's textview value to 2nd activity's textview through getIntent() 从第一个活动的 Edittext 发送字符串到第二个活动的 Edittext - Send String from Edittext on 1st Activity to the Edittext on the 2nd Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM