Imageview As A Splash Screen Not Working
My android app takes some time to initialize, and I'd like to show a splash image before the loading screen appears and hide it afterwards. I searched through stackoverflow and fou
Solution 1:
You should made theme for your splash activity like:
<stylename="AppTheme.Splash"parent="YOURMAIN_THEME"><itemname="android:windowBackground">@drawable/splash_bg</item></style>
And create your splash in drawable directory splash_bg.xml like:
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/splash_background"/><itemandroid:top="30dp"><bitmapandroid:gravity="top"android:src="@drawable/demo_logo"
/></item><item><bitmapandroid:gravity="center"android:src="@drawable/demo_emlogo"/></item></layer-list>
Solution 2:
Add this line in your onCreate(Bundle savedInstance) method:
mImageView = newImageView(this);
mImageView.setScaleType(ScaleType.FIT_XY);
mImageView.setImageResource(R.drawable.splash_bg);
LayoutParamsimageViewLayoutParams=newLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mImageView.setLayoutParams(imageViewLayoutParams);
Solution 3:
xml for splash screen.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_splash_screen" />
</RelativeLayout>
In MainActivity
publicclassSplashextendsActivity {
private final int SPLASH_DISPLAY_LENGHT = 1000;
@Override
publicvoidonCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
new Handler().postDelayed(new Runnable() {
@Override
publicvoidrun() {
Intent mainIntent = new Intent(Splash.this,
MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
Post a Comment for "Imageview As A Splash Screen Not Working"