当我使用View.GONE设置可见性时,我所包含的布局不会填满整个空间

时间:2012-04-01 19:01:22

标签: android commonsware-cwac

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

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

我实际上是想用这种方法解决这个问题: 我的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);

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

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

更新: 我尝试仅使用加载布局设置contentview(参见下面的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 我找到了一个解决方案,它与无休止的适配器无关。见The content of my tabs doesn't fill the whole space

1 个答案:

答案 0 :(得分: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。现在应该填满整个屏幕。

相关问题