[英]Change row height of ListView programmatically in Android app
我正在使用ListView开发一个Android应用程序。
我想以编程方式更改行高,例如第0行的高度为100,其他行的高度为200。
我正在写下以下代码,但是在“ layoutParams.height = 100;”行中 我遇到NullPointerException 。
你能告诉我如何解决这个问题吗?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (mInflater == null){
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if (null == convertView) {
convertView = mInflater.inflate(R.layout.list_detail, null);
}
if (imageLoader == null) imageLoader = AppController.getInstance().getImageLoader();
if(position==0){
ViewGroup.LayoutParams layoutParams = convertView.getLayoutParams();
layoutParams.height = 100;
convertView.setLayoutParams(layoutParams);
}
else{
ViewGroup.LayoutParams layoutParams = convertView.getLayoutParams();
layoutParams.height = 200;
convertView.setLayoutParams(layoutParams);
}
・・・
return convertView;
}
在您的适配器xml中,更改父级的布局高度,您会很方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.