我正在尝试使用固定照片和动画文字制作闪屏。但是,应用程序始终在启动时停止。在logcat中,出现的唯一问题是SplashScreen第17行,更具体地说是这行代码:
setContentView(R.layout.activity_splash_screen);
我的代码:
activity_splash_screen.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.lenovo.tryfinal.SplashScreen">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/garagny"
android:id="@+id/imageView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Park Easily"
android:layout_marginBottom="93dp"
android:textSize="60dp"
android:layout_alignBottom="@+id/imageView"
android:layout_centerHorizontal="true"
android:id="@+id/ParkEasily"/>
</RelativeLayout>
SplashScreen.java
package com.example.lenovo.garagnyapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
public class SplashScreen extends Activity {
TextView ParkEasily;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
ParkEasily = (TextView) findViewById(R.id.ParkEasily);
Animation fade1 = AnimationUtils.loadAnimation(SplashScreen.this, R.anim.fade_in);
ParkEasily.startAnimation(fade1);
ParkEasily.startAnimation(fade1);
fade1.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
startActivity(new
Intent(SplashScreen.this, MainActivity.class));
SplashScreen.this.finish();
}
public void onAnimationRepeat(Animation animation){
}
public void onAnimationStart(Animation animation){
}
});
}
}
fade_in.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="5000" android:repeatCount="infinite"/>
</set>
答案 0 :(得分:2)
您的xml上下文指的是:
工具:上下文=&#34; com.example.lenovo.tryfinal.SplashScreen&#34;
但你的包裹是:
com.example.lenovo.garagnyapplication;
你的xml上下文应该是(tools:context =&#34; com.example.lenovo.garagnyapplication.SplashScreen&#34;)
答案 1 :(得分:0)
我认为你应该导入你的应用程序的R.尝试添加&#34;导入{您的包名} .R&#34;活动类以上的行。如果仍显示错误消息,请清理项目并检查xml文件是否有错误。然后,再次构建并尝试导入生成的R文件。
答案 2 :(得分:0)
您的SplashActivity类位于 com.example.lenovo.garagnyapplication
包中但是你的工具:xml中的上下文是 com.example.lenovo.tryfinal.SplashScreen
让它们相同。在xml中使它
tools:context="com.example.lenovo.garagnyapplication.SplashScreen"