我的列表视图项目下的这个空白空间是什么?
What could this empty spacing under my listview item be?
我扩展了 ArrayAdapter 以扩展我自己的自定义布局(它没有做太多其他事情,而且实现相当简单)。但我注意到在我的列表视图项之间有一条空白 space 的细线:
https://www.evernote.com/l/AM8w6ffsaQhGNJreixsY5fOwDbzTEL7Z73E
我试过设置列表视图项目的高度而不是使用 wrap_content
,没有任何边距,我正在设置列表视图项目的根视图的背景颜色,所以我'我很难弄清楚为什么要添加空 space。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.event_row, parent, false);
holder = new ViewHolder();
holder.time = (TextView) convertView.findViewById(R.id.clock_event_time);
holder.title = (TextView) convertView.findViewById(R.id.clock_event_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ClockEvent clockEvent = mClockEvents.get(position);
holder.time.setText(
ClockUtil.halfHourIndexToHourString(clockEvent.getStartHalfHourIndex())
+ " - " +
ClockUtil.halfHourIndexToHourString(clockEvent.getEndHalfHourIndex())
);
holder.title.setText(clockEvent.getTitle());
convertView.setBackgroundColor(clockEvent.getColor());
return convertView;
}
这里是 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:background="@color/flatui_blue_1"
android:padding="12dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical">
<com.compscieddy.foraday.ui.ForadayTextView
android:id="@+id/clock_event_time"
android:layout_height="wrap_content"
android:background="@drawable/rounded_white_outline"
app:fontface="montserrat_light"
android:paddingTop="2dp"
android:paddingBottom="2dp"
tools:text="7:00 - 8:00"
android:textSize="11sp"
style="@style/EventTimeTextView"/>
<com.compscieddy.foraday.ui.ForadayTextView
android:id="@+id/clock_event_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Early Morning Jog"
android:textColor="@android:color/white"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
因为它是 ListView
这可能是它的分隔符。参见dividerHeight
,可以在xml或java中设置,去掉分隔符。
android:dividerHeight="0dp"
// or
listView.setDividerHeight(0);
啊 - 真是个菜鸟,我忘记了存在 dividerHeight 的默认样式。通过将 android:dividerHeight
设置为 0dp
来解决。也可以添加 style/theme.
我扩展了 ArrayAdapter 以扩展我自己的自定义布局(它没有做太多其他事情,而且实现相当简单)。但我注意到在我的列表视图项之间有一条空白 space 的细线:
https://www.evernote.com/l/AM8w6ffsaQhGNJreixsY5fOwDbzTEL7Z73E
我试过设置列表视图项目的高度而不是使用 wrap_content
,没有任何边距,我正在设置列表视图项目的根视图的背景颜色,所以我'我很难弄清楚为什么要添加空 space。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.event_row, parent, false);
holder = new ViewHolder();
holder.time = (TextView) convertView.findViewById(R.id.clock_event_time);
holder.title = (TextView) convertView.findViewById(R.id.clock_event_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ClockEvent clockEvent = mClockEvents.get(position);
holder.time.setText(
ClockUtil.halfHourIndexToHourString(clockEvent.getStartHalfHourIndex())
+ " - " +
ClockUtil.halfHourIndexToHourString(clockEvent.getEndHalfHourIndex())
);
holder.title.setText(clockEvent.getTitle());
convertView.setBackgroundColor(clockEvent.getColor());
return convertView;
}
这里是 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:background="@color/flatui_blue_1"
android:padding="12dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical">
<com.compscieddy.foraday.ui.ForadayTextView
android:id="@+id/clock_event_time"
android:layout_height="wrap_content"
android:background="@drawable/rounded_white_outline"
app:fontface="montserrat_light"
android:paddingTop="2dp"
android:paddingBottom="2dp"
tools:text="7:00 - 8:00"
android:textSize="11sp"
style="@style/EventTimeTextView"/>
<com.compscieddy.foraday.ui.ForadayTextView
android:id="@+id/clock_event_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Early Morning Jog"
android:textColor="@android:color/white"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
因为它是 ListView
这可能是它的分隔符。参见dividerHeight
,可以在xml或java中设置,去掉分隔符。
android:dividerHeight="0dp"
// or
listView.setDividerHeight(0);
啊 - 真是个菜鸟,我忘记了存在 dividerHeight 的默认样式。通过将 android:dividerHeight
设置为 0dp
来解决。也可以添加 style/theme.