有些时候使用Gridview不想要它下滑,希望自己能设置它的行高,正常情况下GridView是没有设置height的属性的,
我们只能去他的适配器Adapter里面逐个设置它子View来实现高度的设置。下面我就贴下具体的实现方法,方便以后回
顾学习。
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(context).inflate(R.layout.item, null);
convertView.setLayoutParams(
new GridView.LayoutParams((int) (parent.getWidth() / COLUMN_NUMBER),
(int) (parent.getHeight() / RAW_NUMBER)));
convertView.setLayoutParams(param);
return convertView;
column_number 指的是列数,raw_number指的是行数
本文介绍了一种在Android中自定义GridView行高的方法。通常情况下,GridView并没有直接提供设置行高的属性,文中给出的解决方案是在Adapter中通过LayoutParams来设置每个子View的高度。
647

被折叠的 条评论
为什么被折叠?



