通过Android Studio启动屏幕
我正在尝试为我的android应用程序构建一个包含背景图像的启动屏幕。我的问题是,我可以在Android Studio的designer选项卡中很好地看到图像,但当我将应用程序运行到我的物理设备中时,图像不在那里,只有一个黑屏通过Android Studio启动屏幕,android,splash-screen,Android,Splash Screen,我正在尝试为我的android应用程序构建一个包含背景图像的启动屏幕。我的问题是,我可以在Android Studio的designer选项卡中很好地看到图像,但当我将应用程序运行到我的物理设备中时,图像不在那里,只有一个黑屏 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:l
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@Drawable/splash_1">
</LinearLayout>
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
int myTimer = 10000; //Muuttuja "myTimer" määrittää kauan splash näkyy
new Handler().postDelayed(new Runnable(){
@Override
public void run(){
//Muuttuja "i" käskee avaamaan MainActivity
Intent i = new Intent(Splash.this, MainActivity.class);
startActivity(i);
finish();
}
}, myTimer);
}}
公共课堂活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
int myTimer=10000;//Muuttuja“myTimer”märittäkauanäkyy
new Handler().postDelayed(new Runnable()){
@凌驾
公开募捐{
//Muuttuja“i”käskee Avamaan主要活动
意图i=新意图(Splash.this、MainActivity.class);
星触觉(i);
完成();
}
},myTimer);
}}
所以我确实编辑了一下我的布局,但仍然不起作用避免使用特定的宽度和高度尺寸。发生的情况是,您的设备的屏幕比您指定的屏幕小,并且系统将图像“推”到下一行(在本例中,该行被计算为图像的高度) 将图像的宽度和高度设置为
匹配\u parent
并添加
android:scaleType="centerCrop"
或
取决于你喜欢哪个
同时从ImageView
中删除orientation
属性,该属性仅在LinearLayout
元素上有效
注:
您的main活动
可能会在10秒后启动,即使您按下启动屏幕上的后退按钮。对此有一个解决方案-请参见此处:
编辑-建议布局:
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/splash_1"/>
每次运行应用程序时,不要浪费用户10秒的时间。做一次,他们会生气的。做两次,他们就会卸载。我相信10s只用于测试,但我同意:闪屏是邪恶的,不要使用它。您的用户希望快速进入业务,而不是等待启动屏幕。感谢您的贡献,但即使有了这些新的线条,我仍然无法将图像显示在Galaxy S4上。您能否将整个活动\u启动布局编辑到您的问题中?
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/splash_1"/>