我的壞,這是對我而言非常愚蠢:PI是相當可笑的印象是,如果我在XML佈局把一個TextView隨機的地方,然後將其設置爲列表中的空視圖,它會在幻燈片中消失,然後在列表爲空時重新出現在列表中。我想我認爲列表將它添加爲列表中的一行時,它的適配器是空的。在不太可能的情況下,即使其他人決定嘗試類似荒唐的事情,並想知道發生了什麼,我會發布完整版本的原始佈局以及解決方案。
我用來設置空視圖中的代碼是標準:
mListView.setEmptyView(findViewById(R.id.empty));
但是我原來的佈局是這樣的:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="200sp"
>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="@string/drafts"
/>
<ListView android:id="@+id/drafts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="60sp"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:text="@string/finished"
/>
<ListView android:id="@+id/finished"
android:layout_width="fill_parent"
android:layout_height="60px"
android:minHeight="60px"
/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="@string/uploaded"
/>
<ListView android:id="@+id/uploaded"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="60sp"
/>
<TextView
android:id="@+id/empty"
android:text="DUDE WHERE'S MY CAR?"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
雖然我的列表視圖,有一個了minHeight 60sp,當列表爲空時,高度似乎變爲0.另外,我注意到TextView在我所有列表中的三個列表之下都是可見的,所以它似乎沒有「消失」並且再次出現在我的列表中排成一排。多麼令人失望!在我的總體監督下,爲了測試,我將視圖設置爲僅用於第二個列表的emptyView,確保我的第一個和第二個列表爲空,並填充第三個列表。我的第一個名單有它的最小高度,我的第二個縮小到0,我的第三個名單正確填充,我的空視圖出現在它下面。我沒有嘗試填充第二個列表,因此從未意識到空視圖隨後會消失。
最後,花了一個多小時的時間玩動態生成的空視圖和什麼東西,我離開了一天,今天回來,並測試填充第二個列表。瞧,空視圖消失,燈泡繼續。我很快測試了將第二個列表下方的空白視圖移到第三個列表上方,當然,它完美地工作!
這裏是新的工作佈局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="200sp"
>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="@string/drafts"
/>
<ListView android:id="@+id/drafts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:text="@string/finished"
/>
<ListView android:id="@+id/finished"
android:layout_width="fill_parent"
android:layout_height="60px"
android:minHeight="60px"
/>
<TextView
android:id="@+id/empty"
android:text="DUDE WHERE'S MY CAR?"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="@string/uploaded"
/>
<ListView android:id="@+id/uploaded"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
朗的答案,可能只是在自言自語,但不管是誰 - 問的問題,理解了它,我似乎從來沒有能夠在這裏回答別人的問題,所以我不妨回答我自己的:)