【发布时间】:2016-10-30 16:32:23
【问题描述】:
我的主要活动中有以下代码
public class MainActivity extends AppCompatActivity {
ImageView my_flash_screen;
DB db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
my_flash_screen= (ImageView) findViewById(R.id.my_flash_screen);
MainTask task = new MainTask();
task.execute();
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new AlphaAnimation(0.0F, 1.0F));
animation.addAnimation(new ScaleAnimation(0.0f, 1, 0.0f, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)); // Change args as desired
animation.setDuration(1500);
my_flash_screen.startAnimation(animation);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
Intent i = new Intent(MainActivity.this, NavigationActivity.class);
startActivity(i);
finish();
}
}.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class MainTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
if(FontUtil.storeSharedPreference(getApplicationContext()).getString("font", "").isEmpty())
{
FontUtil.savePrefs("font", "SKN.TTF",getApplicationContext());
FontUtil.savesize("fb",22, getApplicationContext());
Log.d("Test","insidefont");
}
try {
if(db==null){
db=new DB(getApplicationContext());
db.createdatabase();
Log.d("Test","intialise first");
}
Log.d("Test","intialise second");
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onCancelled() {
super.onCancelled();
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="@drawable/mynew"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:srcCompat="@drawable/mynew"
android:id="@+id/my_flash_screen"
android:contentDescription="loading image" />
</LinearLayout>
有时当我打开我的应用程序时,只会显示白屏。我使用 AsyncTask 将数据库从资产文件夹复制到设备,共享首选项将设置字体类型和大小。谁能帮我解决这个问题。谢谢.
在提问之前,我已经阅读了以下问题
White background when Android app start up
white background for few seconds before splash screen android
【问题讨论】:
标签: android android-layout material-design