0

我的主 xml 文件中有 2TextViews和 2ListViews和一个EditText

“搜索”EditText首先是“工具” TextView,然后是“工具” ListView,然后是“文章” TextView,然后是“文章” ListView

我想要做的是"No Results Found for Tools"当有人输入一个单词(即“test”)并且它在我的 sql 中不存在时显示,我想在我的工具部分和"No Results found for Articles"我的文章部分中显示它

我的主要问题是,当我运行项目时,textViews 之间有很大的空间。看起来像这样

No Results Found in Tools




No Results Found in Articles.

我想要实现的输出是:

No Results Found in Tools

No Results Found in Articles

我尝试将列表视图的可见性设置为消失,但仍然无法正常工作。你能帮助我吗?

编辑:这是我的 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:background="@color/white"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/navbar_search"
        android:paddingLeft="5dp" >

        <ImageView
            android:id="@+id/buttonBack"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/btn_back" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/violet"
        android:padding="5dp" >

        <EditText
            android:id="@+id/editTextSearch"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_search"
            android:paddingLeft="35dp" >
        </EditText>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editTextSearch"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:src="@drawable/search" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@color/blue"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp" >

        <TextView
            android:id="@+id/textArticlesResult"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:text="@string/label_articles"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black"
            android:textStyle="bold" />

        <ListView
            android:id="@+id/listViewArticlesResult"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/textArticlesResult"
            android:cacheColorHint="@color/white"
            android:fadeScrollbars="false" >
        </ListView>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@color/blue"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp" >

        <TextView
            android:id="@+id/textToolsResult"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="@string/label_tools"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black"
            android:textStyle="bold" 
            android:layout_below = "@id/listViewArticlesResult" />

        <ListView
            android:id="@+id/listViewToolsResult"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/textToolsResult"
            android:cacheColorHint="@color/white"
            android:fadeScrollbars="false" >
        </ListView>
    </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="46dp" >

        <ImageView
            android:id="@+id/tabHome"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:contentDescription="@string/desc"
            android:scaleType="fitXY"
            android:src="@drawable/tab_home_unselected" />

        <ImageView
            android:id="@+id/tabFb"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:contentDescription="@string/desc"
            android:scaleType="fitXY"
            android:src="@drawable/tab_fb_unselected" />

        <ImageView
            android:id="@+id/tabSearch"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:contentDescription="@string/desc"
            android:scaleType="fitXY"
            android:src="@drawable/tab_search_selected" />

        <ImageView
            android:id="@+id/tabFaves"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:contentDescription="@string/desc"
            android:scaleType="fitXY"
            android:src="@drawable/tab_myfaves_unselected" />

        <ImageView
            android:id="@+id/tabSettings"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:contentDescription="@string/desc"
            android:scaleType="fitXY"
            android:src="@drawable/tab_settings_unselected" />
    </LinearLayout>

</LinearLayout>
4

1 回答 1

0

您的代码块:`

    <TextView
        android:id="@+id/textArticlesResult"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:text="@string/label_articles"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/black"
        android:textStyle="bold" />

    <ListView
        android:id="@+id/listViewArticlesResult"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/textArticlesResult"
        android:cacheColorHint="@color/white"
        android:fadeScrollbars="false" >
    </ListView>
</RelativeLayout>`

替换为:

<TextView
    android:id="@+id/textArticlesResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:text="@string/label_articles"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/black"
    android:textStyle="bold" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="@color/blue"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="5dp"
    android:visibility="visible" >

    <ListView
        android:id="@+id/listViewArticlesResult"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="@color/white"
        android:fadeScrollbars="false"
        android:visibility="visible" >

    </ListView>

</RelativeLayout>

并修改android:visibility其中RelativeLayout封装了您的ListView

于 2013-01-04T01:06:08.203 回答