我正在尝试使用滑动库制作启动画面但是 即使经过多次尝试,我也无法启动闪屏。 我是否必须使用异步任务,我将如何开始一项活动 启动画面后。我用过
我的build.gradle(模块)中的 com.master.android:glideimageview:1.0
和com.github.bumptech.glide:glide:4.0.0-RC1
请指导我?
这是我的代码:
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();
}
}
答案 0 :(得分:1)
像这样使用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
}
答案 1 :(得分:1)
使用此代码
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashScreenActivity.this, LoginActivity.class));
}
}, 2000);