我已经完成this& this提出问题,但无法弄清楚为什么列表视图的第一项不可见。我检查了arraylist的大小,这是正确的。
listview文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/videoListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp" />
</RelativeLayout>
listview项目xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<ImageView
android:layout_width="150dp"
android:layout_height="90dp"
android:id="@+id/videoImageView"
android:layout_marginLeft="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="35dp"
android:id="@+id/titleTextView"
android:layout_marginRight="10dp"
android:layout_toRightOf="@+id/videoImageView"
android:layout_marginLeft="10dp"
android:textSize="12sp"
android:textColor="#000000"
android:ellipsize="end"
android:maxLines="2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:id="@+id/timeTextView"
android:layout_alignStart="@+id/titleTextView"
android:layout_alignLeft="@+id/titleTextView"
android:layout_below="@+id/titleTextView"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/downloadImageView"
android:layout_alignStart="@+id/timeTextView"
android:layout_alignLeft="@+id/timeTextView"
android:layout_below="@+id/timeTextView"
android:layout_alignBottom="@+id/videoImageView"
android:src="@drawable/ic_vector_download"
android:layout_marginTop="5dp"/>
<ProgressBar
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/downloadProgressBarView"
android:layout_alignStart="@+id/timeTextView"
android:layout_alignLeft="@+id/timeTextView"
android:layout_below="@+id/timeTextView"
android:layout_alignBottom="@+id/videoImageView"
android:layout_marginTop="5dp"
android:visibility="gone"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/shareImageView"
android:layout_below="@+id/timeTextView"
android:layout_alignBottom="@+id/videoImageView"
android:layout_toRightOf="@+id/downloadImageView"
android:layout_marginTop="5dp"
android:layout_marginLeft="7dp"
android:src="@drawable/ic_vector_share"/>
</RelativeLayout>
适配器类:
public class OfflineVideoAdapter extends ArrayAdapter<OfflineVideo> {
Context context;
OfflineVideoDBHelper db;
List<OfflineVideo> list;
public OfflineVideoAdapter(Context context, int resource, List<OfflineVideo> list) {
super(context, resource, list);
this.context = context;
this.list = list;
}
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final OfflineVideoHolder holder;
if (convertView == null) {
holder = new OfflineVideoHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.video_list_item, parent, false);
holder.video = (ImageView)convertView.findViewById(R.id.videoImageView);
holder.title = (TextView)convertView.findViewById(R.id.titleTextView);
holder.publishedAt = (TextView)convertView.findViewById(R.id.timeTextView);
holder.delete = (ImageView)convertView.findViewById(R.id.downloadImageView);
holder.share = (ImageView)convertView.findViewById(R.id.shareImageView);
convertView.setTag(holder);
} else {
holder = (OfflineVideoHolder)convertView.getTag();
}
final OfflineVideo offlineVideo = getItem(position);
Picasso.with(context).load(offlineVideo.imageURL).into(holder.video);
holder.title.setText(offlineVideo.title);
holder.publishedAt.setText(CommonUtils.calculateTime(offlineVideo.publishedAt));
holder.delete.setImageResource(R.drawable.ic_vector_delete);
return convertView;
}
}
答案 0 :(得分:4)
检查工具栏是否在listviews第一项
上没有重叠答案 1 :(得分:0)
将ListView
属性layout_width
和layout_height
更改为Fill_Parent
它对我有用。
答案 2 :(得分:-1)
我遇到了同样的问题,因为我的ListView
layout_width
和layout_height
是"match_constraint"
,并且工具栏与第一项重叠。只需调整ListView
的高度即可。它对我有用。