Android 尝试滚动时Gridview滚动被卡住
我有一个网格视图,我试图在其中激光扫描大量数据, 如果我尝试在Gridview中重用LayoutFlater,则项目会重复,如果我尝试加载新布局,则在这种情况下,滚动卡住了我应该做什么。以下是我正在使用的代码:Android 尝试滚动时Gridview滚动被卡住,android,android-gridview,Android,Android Gridview,我有一个网格视图,我试图在其中激光扫描大量数据, 如果我尝试在Gridview中重用LayoutFlater,则项目会重复,如果我尝试加载新布局,则在这种情况下,滚动卡住了我应该做什么。以下是我正在使用的代码: if (convertView == null) { // if it's not recycled, initialize some if (DownloadModualActivity.count_screen_normal == 1) { LayoutInf
if (convertView == null) { // if it's not recycled, initialize some
if (DownloadModualActivity.count_screen_normal == 1) {
LayoutInflater li = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.magazine_container_mobile, parent,
false);
// v = li.inflate(R.layout.magazine_container_mobile, null);
}
if (DownloadModualActivity.count_screen_normal != 1) {
LayoutInflater li = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// v = li.inflate(R.layout.magazine_container4, null);
v = li.inflate(R.layout.magazine_container4, parent, false);
}
} else {
v = (View) convertView;
}
查看ListView的站点、性能提示和模式。您可以将其应用于gridview
检查异步加载,如果您有繁重的操作,则应在异步任务中加载以释放ui线程。据我所知,您正在尝试将两个不同的视图附加到列表视图。那么你需要的就是这些方法。执行这些方法并重试
@Override
public int getItemViewType(int position) {
// you need to return the index of your view you want to return according to your
// algorithm.
return 0;
}
@Override
public int getViewTypeCount() {
return 2;
}
在getView()方法中,您可以使用下面的方法
@Override
public View getView(int position, View convertView, ViewGroup parent) {
YourDataModel item = getItem(position);
switch (getItemViewType(position)) {
case 0:
return getViewFirstItem(position, convertView, item);
case 1:
return getViewSecondItem(position, convertView, item);
}
return null;
}
在getViewFirstItem()和getViewSecondItem()中,尝试为两种不同的视图类型实现两个不同的getView版本