[英]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.