我想通过GridLayoutManager使用setSpanSizeLookup进行这种布局。 有人知道如何通过计算项目宽度自动调整项目并自动调整像图像? 如果还有其他方法,那么请给我建议。由于如何使用setSpanSizeLookup自动调整项目?
下面是一些代码:
int maxWidth=1040; // device width
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
LayoutInflater vi = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.row_favorite, null);
final TextView textView = (TextView) v.findViewById(R.id.tv_name);
int itemWidth = (int) (textView.getPaint().measureText(favoriteList.get(position).getName()));
if ((maxWidth/2)/3 > itemWidth) {
return 1;
} else if ((maxWidth/2)/3 < itemWidth && maxWidth/3 > itemWidth) {
return 2;
} else if (maxWidth/2 > itemWidth && maxWidth/3 < itemWidth) {
return 3;
}
});
检查图像
检查该[库]( https://github.com/DavidPizarro/AutoLabelUI) –
我想显示大量的记录,所以我更喜欢使用recyclerView,我已经应用了一些l但他们freez视图等。我接近上述方法,但有时计算出错。我认为** setSpanSizeLookup **是正确的方式..期待..谢谢你的建议库@BurakCakir –
如果视图不冻结在你正在申请的方法,只有问题在计算中,你可以应用上述库的计算到你自己的代码。 –