Introduction
Whether it's Android or iOS, you can see that some apps start with a splash screen (Splash Activity), such as QQ, etc. This splash screen often hides the Actionbar and status bar, and then the user enters a state of immersion that creates a more intense visual impact. On the one hand, this can give users a deeper experience to use, resulting in a certain brand effect; On the other hand, it also leaves ample time for the startup initialization of the application to avoid leaving a bad impression on the user because of the long boot time. Therefore, full-screen display in the mobile phone application has been widely used. Then this blog will record the full-screen display of some of the implementation.
Realize
Scenario One: Set the background picture for the layout manager. This approach is implemented by setting Android:background and Noactionbar themes.
1 <!--Base application theme. -2 <stylename= "Apptheme"Parent= "Theme.AppCompat.Light.NoActionBar">3 <!--Customize your theme here. -4 <Itemname= "Colorprimary">@color/colorprimary</Item>5 <Itemname= "Colorprimarydark">@color/colorprimarydark</Item>6 <Itemname= "Coloraccent">@color/coloraccent</Item>7 </style>
<Relativelayoutxmlns: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:background= "@drawable/background"Tools:context= "Com.hnb.zzk.clippingtest.MainActivity"> <ImageViewAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:adjustviewbounds= "false"> </ImageView></Relativelayout>
Here @drawable/background is a picture resource placed in the drawable directory. At this point, it is still a pity that the status bar is still not hidden, so the method is also called to hide the status bar:
Requestwindowfeature (Window.feature_no_title); GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Scenario two, add a full-screen child view ImageView in Framelayout. Specifically, ImageView is used as the first child of the Framelayout, based on the Framelayout attribute, and the child views added later are superimposed on the first child view, which indirectly implements the full picture view background.
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Tools:context= "Com.hnb.zzk.clippingtest.MainActivity">7 8 <ImageView9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Match_parent" One Android:adjustviewbounds= "false" A android:src= "@drawable/background" - Android:scaletype= "Centercrop"> - the </ImageView> - - </Framelayout>
In the Java code, the same setting:
1 requestwindowfeature (window.feature_no_title); 2 GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_ fullscreen);
There is no difference between the results and the scheme. Be aware, however, that when loading a picture with a larger resolution, or when the picture is large, memory overflow is easily caused.
Scenario Three: Use Java code to load the picture dynamically to set the full screen background. The idea is to scale the image to fit the screen size, depending on the size of the display screen.
/* Create a full screen window */requestwindowfeature (window.feature_no_title); GetWindow (). SetFlags ( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); Setcontentview ( r.layout.your_activity);/* Adapt the image to the size of the display */display display = Getwindowmanager (). Getdefaultdis Play (); Point size = new Point ();d isplay.getsize (size); Bitmap bmp = Bitmap.createscaledbitmap (Bitmapfactory.decoderesource ( getresources (), R.drawable.background), SIZE.X,SIZE.Y,TRUE);/* Fill the background ImageView with the resized image */imageview Iv_background = (ImageView) findvi Ewbyid (R.id.iv_background); Iv_background.setimagebitmap (BMP);
Reference
- Http://stackoverflow.com/questions/16135984/full-screen-background-image-in-an-activity
Full-screen background display scheme in Android development