0
我試圖從谷歌GridView示例中編寫一個簡單的GridView適配器;這裏是我的getView函數。爲GridView編譯android例子時出錯
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridLayout.LayoutParams(120,120));
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setPadding(2, 2, 2, 2);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
,但我得到一些像這樣的錯誤此行imageView.setLayoutParams(new GridLayout.LayoutParams(120,120));
Error:(39, 39) error: no suitable constructor found for LayoutParams(int,int)
constructor android.widget.GridLayout.LayoutParams.android.widget.GridLayout.LayoutParam (Context,AttributeSet) is not applicable
(actual argument int cannot be converted to Context by method invocation conversion)
constructor android.widget.GridLayout.LayoutParams.android.widget.GridLayout.LayoutParams(android.widget.GridLayout.LayoutParams) is not applicable
(actual and formal argument lists differ in length)
constructor android.widget.GridLayout.LayoutParams.android.widget.GridLayout.LayoutParams(MarginLayoutParams) is not applicable
(actual and formal argument lists differ in length)
constructor android.widget.GridLayout.LayoutParams.android.widget.GridLayout.LayoutParams(android.view.ViewGroup.LayoutParams) is not applicable
(actual and formal argument lists differ in length)
constructor android.widget.GridLayout.LayoutParams.android.widget.GridLayout.LayoutParams() is not applicable
(actual and formal argument lists differ in length)
constructor android.widget.GridLayout.LayoutParams.android.widget.GridLayout.LayoutParams(Spec,Spec) is not applicable
(actual argument int cannot be converted to Spec by method invocation conversion)
有沒有什麼解決辦法嗎?