[英]Android GridView Scrolling issue
I'm facing a Problem, that my GridView "clips"/"glitches" after I scroll to the 4th row or longer than 2 seconds.我面临一个问题,我的 GridView 在我滚动到第 4 行或超过 2 秒后“剪辑”/“故障”。
I got 58 Items, which get loaded via a Adapter into the GridView.我有 58 个项目,它们通过适配器加载到 GridView。 An Item consists of a filename and an Image of the Item (Thumbnail).
一个项目由一个文件名和一个项目的图像(缩略图)组成。 Each Thumbnail has a width and height of 100dp and is loaded into a ImageButton via the Framework "Glide" without resizing, crop or anything else.
每个缩略图的宽度和高度为 100dp,并通过框架“Glide”加载到 ImageButton 中,无需调整大小、裁剪或其他任何内容。 Simple
Glide.load(ressource).into(imageButton)
.简单
Glide.load(ressource).into(imageButton)
。
Please see the attached images to follow my further explanation.请参阅所附图片以遵循我的进一步解释。
After Scrolling I would expect, that my Items are Aligned like the first 15-19 Items before.滚动后,我希望我的项目像之前的前 15-19 个项目一样对齐。 Unfortunately it is scrolling only the "last Item" of the 4th row from the GridView.
不幸的是,它仅滚动 GridView 第四行的“最后一项”。 That mean's that at Point 2 (red digit within the Picture) all the other items appearing for a short period if I scroll through them.
这意味着在第 2 点(图片中的红色数字),如果我滚动浏览它们,所有其他项目会在短时间内出现。
After scrolling further the whole GridView and Scrollbar get's "destroyed" and only a small amount of Item's appear and lastly 1 or none item's appear.进一步滚动后,整个 GridView 和 Scrollbar 被“破坏”,只出现少量项目,最后出现 1 个或没有项目。 I can see, that the Scrollbar is decreasing very fast, after scrolling.
我可以看到,滚动条在滚动后下降得非常快。
GridView xml Properties (within main_activity.xml): GridView xml 属性(在 main_activity.xml 中):
android:columnWidth="100dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:verticalSpacing="20dp"
android:visibility="visible"
GridViewAdapter Code: GridViewAdapter 代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
_layoutInflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
_view = new View(_context);
_view = _layoutInflater.inflate(R.layout.single_item, null);
TextView textView = _view.findViewById(R.id.textView);
final Item item = _items.get(position);
textView.setText(item.getName());
ImageButton imageButton = _view.findViewById(R.id.imageButton);
Glide.with(_context).load(item.getDrawableRessource()).into(imageButton);
imageButton.setOnClickListener(click -> {
_iOnItemClickListener.onClick(item);
});
}
return _view;
}
Thanks for any helpful advice.感谢您提供任何有用的建议。
Try this:尝试这个:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
_view = convertView;
if (convertView == null) {
_layoutInflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
_view = _layoutInflater.inflate(R.layout.single_item, null);
}
TextView textView = _view.findViewById(R.id.textView);
final Item item = _items.get(position);
textView.setText(item.getName());
ImageButton imageButton = _view.findViewById(R.id.imageButton);
Glide.with(_context).load(item.getDrawableRessource()).into(imageButton);
imageButton.setOnClickListener(click -> {
_iOnItemClickListener.onClick(item);
});
return _view;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.