RelativeLayout中的ListView不显示

时间:2014-09-17 02:04:53

标签: android listview relativelayout

我正在编写一个应用程序并遇到了一些问题。 使用布局文件时,我在 ViewFlipper 中有2 RelativeLayouts

这个想法是这个页面特别是一个欢迎屏幕。第一个RelativeLayout“欢迎”您使用该应用程序,按下按钮后,用户将被引导至第二个RelativeLayout。在此布局中,有一个搜索栏,允许用户搜索特定条件(特定于应用程序,不重要),然后在 ListView 中显示结果。

一切正常,但显示ListView似乎有一些问题。适配器设置正确,我在测试布局中的另一个ListView上测试了该方法,并且它工作正常。但是,RelativeLayout中的ListView似乎有些问题。这是布局代码

activity_welcome.xml

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/welcomeFlipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:animateLayoutChanges="true"
    android:background="@color/white"
    tools:context="com.jacemcpherson.announcer.WelcomeActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:padding="40dp">

        ...
        <!-- This code irrelevant, all's well :) -->

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:background="@color/white"
        android:padding="40dp">

        <TextView
            android:id="@+id/textFirstThingsFirst"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/textYouNeedToSearch"
            android:layout_centerHorizontal="true"
            android:text="@string/first_things_first"
            android:textColor="@color/app_color"
            android:textSize="32sp" />

        <TextView
            android:id="@+id/textYouNeedToSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_margin="10dp"
            android:gravity="center"
            android:text="@string/you_need_to_search_for_your_school"
            android:textColor="@color/black"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/schoolSearchEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textYouNeedToSearch"
            android:hint="@string/search_hint" />


        <ProgressBar
            android:id="@+id/searchListProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/schoolSearchEditText"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:visibility="gone" />

        <!-- This is the problem area -->
        <ListView
            android:id="@+id/searchResultsList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/schoolSearchEditText" />

    </RelativeLayout>
</ViewFlipper>

我设置的适配器工作正常,但万一我错过了什么,这里是的代码行 ......

mListView.setAdapter(new ArrayAdapter<String>(
    mContext,
    android.R.layout.simple_list_item_1,
    result     // this is the array of results to be displayed in the list.
));

感谢您的帮助,如果我错过了一些在没有进一步信息的情况下无法解决的问题,请告诉我。

1 个答案:

答案 0 :(得分:2)

layout_heightwrap_content更改为match_parentfill_parent

this answer解释了这一点。