2014-05-24 21 views
0

我想爲Android應用創建標題屏幕。該屏幕是一個簡單的XML文件,其中包含一個圖像。基本上,屏幕將顯示,直到其他一些東西完成加載,屏幕將變成應用內容。問題是,很多時候XML中的圖像根本沒有出現 - 我得到的只是一個空白的xml頁面,然後加載應用程序。我假設是因爲加載圖像完成異步或什麼。我試圖使用Thread.sleep,這被證明是一個壞主意。
任何人有一個想法如何得到這個工作?
謝謝!
主要XML:如何在xml中等待ImageView完成加載

<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" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="128dp" 
    android:src="@drawable/icon" /> 

主要活動:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    <do some stuff> 
    start_other_activity_with_different_xml(); 

回答