我正在研究android项目,我正在处理启动画面代码,但是在我的手机的整个屏幕上没有显示启动图像我的活动代码是: -
public class SplashPresenter extends MvpBasePresenter<SplashView> {
@Override public void attachView(SplashView view) {
super.attachView(view);
new Handler().postDelayed(new Runnable() {
@Override public void run() {
launch();
}
}, 2000);
}
@Override public void detachView(boolean retainInstance) {
super.detachView(retainInstance);
}
private void launch() {
String imei = ImeiUtil.getIMEI();
List<ActivationInfo> infos = ActivationInfo.listAll(ActivationInfo.class);
if (infos.size() == 1) {
ActivationInfo info = infos.get(0);
/*
Log.d("I: ", "I: " + info.getBusinessName());
Log.d("I: ", "I: " + info.getMobileNumber());
Log.d("I: ", "I: " + info.getImei());
Log.d("I: ", "I: " + imei);
Log.d("I: ", "S: " + info.getStatus());
*/
if (info.getStatus() == 1 && info.getImei().equalsIgnoreCase(imei)) {
getView().start(HomeActivity.class);
} else {
//getView().start(ActivationActivity.class);
getView().start(HomeActivity.class);
}
} else {
getView().start(HomeActivity.class);
// getView().start(RegisterActivity.class);
}
}
和xml代码,我在这里显示了
<RelativeLayout
xmlns: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"
tools:context=".MainActivity">
<ImageView
android:contentDescription="@string/splash_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/splash_english"/>
</RelativeLayout>
答案 0 :(得分:0)
<RelativeLayout
xmlns: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"
tools:context=".MainActivity">
<ImageView
android:contentDescription="@string/splash_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/splash_english"
android:minHeight="1000dp"
android:minWidth="1000dp"/>
</RelativeLayout>
答案 1 :(得分:0)
如果您只想让图片填满屏幕,请将您的android:scaleType更改为fitXY。依靠minHeight和minWidth并使用centerCrop并不能很好地覆盖多种设备尺寸。更好的解决方案,开发更好尺寸的图像或使用基于xml的drawables
答案 2 :(得分:0)
在活动的onCreate方法
中添加此行getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
答案 3 :(得分:0)
以正确的方式实现启动画面与您想象的有点不同。您看到的启动视图必须立即就绪,甚至在您可以在启动活动中为布局文件充气之前。你不会使用布局文件。而是将启动画面的背景指定为活动的主题背景。为此,首先在res / drawable中创建一个XML drawable。它是xml文件。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
接下来,您将把它设置为主题中的启动活动的背景。导航到styles.xml文件并为启动活动添加新主题:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
</resources>
你的SplashActivity课程应该转发你的主要活动:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
此处提供了完整的源代码供下载https://github.com/shubhamsharmacs/Splash