闪屏出现滑动问题,因为它不工作

Splash screen with glide issue as it is not working

我正在尝试制作一个使用 glide 库的启动画面,但是 即使尝试了很多次,我也无法启动启动画面。 我必须使用异步任务吗?我将如何启动 activity 在闪屏之后。我用过

com.master.android:glideimageview:1.0com.github.bumptech.glide:glide:4.0.0-RC1 在我的 build.gradle(模块) 请指导我?

这是我的代码:

splash.xml

<?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.ConstraintLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <ImageView
    android:contentDescription="@string/splash_bg_cd"
    android:id="@+id/splash_bg"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_width="0dp"
    android:layout_height="0dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/text_splash"
    android:textSize="@dimen/splash_text_size"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

和Java代码Splash.java

import com.bumptech.glide.Glide;
import com.master.glideimageview.*;

public class Splash extends AppCompatActivity {

    private ImageView ivBgSplash;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable 
        PersistableBundle persistentState) {

        super.onCreate(savedInstanceState, persistentState);

        setContentView(R.layout.splash_screen);

        initViews();
     }

     private void initViews() {

        ivBgSplash = (ImageView) findViewById(R.id.splash_bg);
        Glide.with(this)
                .load(R.drawable.hlb_logo)
                .into(ivBgSplash);
        AnimationDrawable splashAnimation = (AnimationDrawable) 
        ivBgSplash.getBackground();
        splashAnimation.start();
     }
}

像这样使用 Handler 启动画面

将此代码添加到您的 onCreate() 方法中

new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, 3000);// times in millisends
}

使用此代码

Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            startActivity(new Intent(SplashScreenActivity.this, LoginActivity.class));
        }
    }, 2000);