Android:ListView最后一项行为怪异

Android:ListView最后一项行为怪异,android,android-listview,selecteditem,Android,Android Listview,Selecteditem,我有一个自定义适配器,我的标题和内容用maxlines和minlines显示。 但是,它只适用于除最后一项之外的所有项目 前几项 最后一项 如您所见,最后一项没有标题,但这不是一个问题。如果长度为零,则不可见 首先,它忽略了适配器中甚至没有设置的文本颜色,而是实际的.xml中的文本颜色。如果我按下该项,它会得到正确的颜色,直到长按动作开始。加上忽略最大线/最小线 最后一个项目的内容与标题为“另一个培根”的项目相同。 。。。。BaseAdapter中的getView() 提示:setMaxLi

我有一个自定义适配器,我的标题和内容用maxlines和minlines显示。 但是,它只适用于除最后一项之外的所有项目

前几项

最后一项

如您所见,最后一项没有标题,但这不是一个问题。如果长度为零,则不可见

首先,它忽略了适配器中甚至没有设置的文本颜色,而是实际的.xml中的文本颜色。如果我按下该项,它会得到正确的颜色,直到长按动作开始。加上忽略最大线/最小线

最后一个项目的内容与标题为“另一个培根”的项目相同。

。。。。BaseAdapter中的getView()
提示:setMaxLines(3);
if(item.getTitle().length()<1){
提示:设置单行(false);
提示.setMinLines(!cards_ui?3:1);
}否则{
提示。设置单行(true);
提示:setMinLines(1);
提示:设置MaxLines(卡和ui?3:1);
}
从项目xml

<LinearLayout ... >

     <TextView
          android:id="@+id/list_item_title"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="5"
          android:paddingLeft="6dp"
          android:paddingRight="6dp"
          android:textSize="20sp"
          android:textColor="@color/black_lite"
          android:textColorHint="@color/black_lite"
          android:singleLine="true"
          android:maxLines="1"
          android:maxEms="10"
          android:ellipsize="end"
          android:hint=""
          android:text=""
          android:textIsSelectable="false" />

     <TextView
          android:id="@+id/list_item_content"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="10"
          android:paddingLeft="6dp"
          android:paddingRight="6dp"
          android:paddingBottom="10dp"
          android:text=""
          android:textSize="15sp"
          android:textColor="@color/black_light"
          android:textColorHint="@color/black_light"
          android:maxLines="3"
          android:ellipsize="end"
          android:textIsSelectable="false" />

</LinearLayout>

列表视图

    <ListView
            android:id="@+id/list_listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:listSelector="@drawable/listview_selector"
            android:dividerHeight="1dp"
            android:clipToPadding="false"
            android:columnWidth="120dp"
            android:drawSelectorOnTop="true"
            android:horizontalSpacing="@dimen/grid_spacing"
            android:numColumns="auto_fit"
            android:padding="@dimen/grid_spacing"
            android:verticalSpacing="@dimen/grid_spacing"
            />


那么,为什么我的最后一个项目得到另一个'风格'?我的代码中没有选择任何项目的内容,我尝试将列表选择器更改为透明但没有差异。

当您使用布局权重和垂直方向(列表是垂直的)时,需要将高度设置为
0dp
,以便自动计算

在您的示例中,您试图提供总高度的标题5/15,内容为10/15


也许这不是您想要的,因为列表项通常应该占据所需的空间,所以
android:layout\u height=“wrap\u content”
已经足够了,应该删除权重。

我删除了权重,但没有区别。问题不在于线路的数量吗?@JonasB您使用的适配器是什么?请将代码张贴在实例化它的地方。
    <ListView
            android:id="@+id/list_listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:listSelector="@drawable/listview_selector"
            android:dividerHeight="1dp"
            android:clipToPadding="false"
            android:columnWidth="120dp"
            android:drawSelectorOnTop="true"
            android:horizontalSpacing="@dimen/grid_spacing"
            android:numColumns="auto_fit"
            android:padding="@dimen/grid_spacing"
            android:verticalSpacing="@dimen/grid_spacing"
            />