1

我不知道这是否是正确的方法,但我希望你能帮助我。

我正在使用 ListActivity 来显示来自 RSS 提要的内容。在加载内容时,我想显示一个挂起的视图。我正在使用该网站https://github.com/commonsguy/cwac-endless的 EndlessAdapter 。它提供了一种显示待处理视图的方法,但是第一次加载数据时它是一个空列表中的一小行,所以它不是很性感。

我实际上是在尝试用这种方法解决这个问题:我的 ListActivity 的自定义布局,其中有一个待处理的视图,我可以在第一次加载时隐藏或显示。布局的 XML 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF"
        android:cacheColorHint="#FFFFFF"/>


    <include
        android:id="@+id/progressBar"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        layout="@layout/loading_anim">
    </include>
</LinearLayout>

第一次加载数据时,我将列表可见性设置为使用此行:

listView.setVisibility(View.GONE);

它几乎可以工作,但包含的布局并没有填满整个屏幕,我知道我不知道如何以正确的方式解决这个问题。

希望有人能帮助我,谢谢!

更新: 我尝试仅使用加载布局设置内容视图(请参阅下面的 XML),我得到了相同的结果(请参阅http://imageshack.us/photo/my-images/594/loadingwf.png/):

this.setContentView(R.layout.loading_anim);

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:gravity="center_horizontal"
    android:orientation="horizontal"
    android:padding="5dp" >

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="@string/loading" />

</LinearLayout>

所以我想知道是否可能是因为标签...有人可以帮助我吗?谢谢

更新 2 我找到了一个解决方案,它与永无止境的适配器无关。请参阅我的选项卡的内容没有填满整个空间

4

1 回答 1

1

在您的 ListView 中,试试这个:

<ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:cacheColorHint="#FFFFFF"/>

我所做的是将 layout_height 设置为 wrap_content。现在应该填满整个屏幕。

于 2012-04-01T19:08:25.200 回答