I am trying to make a splash screen with a fixed photo and animated text. However, the application always stops when launching. In the logcat, the only problem that appears is in SplashScreen line 17, and more specifically this line of code:
setContentView(R.layout.activity_splash_screen);
My code:
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>
Your xml context refers this:
tools:context="com.example.lenovo.tryfinal.SplashScreen"
but your package is:
com.example.lenovo.garagnyapplication;
Your xml contex should be (tools:context="com.example.lenovo.garagnyapplication.SplashScreen")
I think you should import the R of your app. Try add "import {your package name}.R" line above Activity class. If it still shows error message, clean your project and check your xml file whether it has error. Then, build again and try to import generated R file.
Your SplashActivity class is under package com.example.lenovo.garagnyapplication
But your tools:context in xml is com.example.lenovo.tryfinal.SplashScreen
Make them same. in xml make it
tools:context="com.example.lenovo.garagnyapplication.SplashScreen"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.