隐藏的ListView行,不占用空间 [英] Hide row from ListView without taking up space

查看:123
本文介绍了隐藏的ListView行,不占用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示几项活动的内容相关联的ArrayAdapter一个ListView。不幸的是,现在有必要,我在其中一个设置的ListView不显示其所有元素,但只是其中的财产没有设置为true的那些。我想避免使用两个ArrayAdapters不同的内容,自那时以来,我莫名其妙地需要保持同步。我试了一下这样的(这种方法现在只是假设getView被称为在我们想隐藏某些元素的设置):

I have a ListView with an associated ArrayAdapter that displays its contents in several activities. Unfortunately it got necessary now, that my ListView in one of the settings does not display all its elements, but just the ones where "property" is not set to true. I would like to avoid to use two ArrayAdapters with different content, since then I somehow need to keep them in sync. I tried it like this (this method now just assumes that getView is called in the setting where we want to hide certain elements):

public View getView(int position, View convertView, Context context) {
....

    if(!arrayitems[position].isProperty()) { //arrayitems is the underlying array
        convertView.setVisibility(View.VISIBLE); 
    } 
    else {
        convertView.setVisibility(View.GONE); 
    }
    return convertView;
}

这个工作,但是我得到一个白色的行如果元素具有isProperty ==真。我想使该行的意义上看不见的,它不占用任何空间了。这可能吗?

This works, however I get a white row if the element has isProperty == true. I would like to make the row invisible in the sense, that it does not take up any space anymore. Is that possible?

有关convertView的使用的XML文件看起来是这样的:

The used xml file for convertView looks like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/text_item_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="4dp"
            android:maxLines="1"
            android:ellipsize="none"
            android:textSize="12sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/text_item_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:textStyle="bold" />

    </LinearLayout>

     <TextView android:id="@+id/text_item_text"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textSize="12sp"
         android:maxLines="3"
         android:ellipsize="none" />

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="2dp"
         android:orientation="horizontal" >

         <TextView
             android:id="@+id/text_item_rating"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginRight="4dp"
             android:textSize="10sp" />

         <TextView
             android:id="@+id/text_item_voted"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textSize="10sp" />

     </LinearLayout>

</LinearLayout>

我试图重播所有Android:layout_height =WRAP_CONTENT与FILL_PARENT,但它并没有改变什么......

I tried to replay all android:layout_height="wrap_content" with "fill_parent" but it did not change anything...

谢谢!

推荐答案

设置列表视图中经历的所有内容的可见性,然后设置视图飘的知名度....这将隐藏的行不占用空间.....它的工作对我来说,即使我一直在寻找这一点,但研究后,我发现这个....

Set the Visibility of all the contents of the list view to GONE and then set the visibility of the View to Gone.... this will hide the row without occupying space..... it worked for me even i have been searching for this but after a research i found this....

编辑1:
视图的可见性设置为GONE就够了。无需设置子元素的可见性。

EDIT 1 : Setting the visibility of the View to GONE is enough. No need to set the child element's visibility.

这篇关于隐藏的ListView行,不占用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆