繁体   English   中英

飞溅屏幕与滑行问题,因为它不工作

[英]Splash screen with glide issue as it is not working

我试图制作一个使用滑动库的启动画面,但即使在尝试多次后我也无法启动启动画面。 我是否必须使用异步任务,如何在启动画面后启动活动。 我用过

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);

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM