Android studio 我一直在SetLayoutParams上出错-无法从静态上下文引用?
我已经从android studio粘贴了下面的整个类。我正在尝试使用图像视图和网格视图创建图库。Android studio 我一直在SetLayoutParams上出错-无法从静态上下文引用?,android-studio,android-imageview,android-context,layoutparams,Android Studio,Android Imageview,Android Context,Layoutparams,我已经从android studio粘贴了下面的整个类。我正在尝试使用图像视图和网格视图创建图库。 package com.example.sc.loginappexercise; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.GridView; im
package com.example.sc.loginappexercise;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
/**
* Created by sc on 16/03/2017.
*/
public class ImageAdapter extends BaseAdapter {
public Context context;
public int[] images = {
R.drawable.gallery1, R.drawable.gallery2,
R.drawable.gallery3, R.drawable.gallery4,
R.drawable.gallery5, R.drawable.gallery6,
R.drawable.gallery7, R.drawable.gallery8,
R.drawable.gallery9, R.drawable.gallery10,
};
public ImageAdapter(Context c){
context = c;
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object getItem(int position) {
return images [position];
}
@Override
public long getItemId(int position) {
return 0;
}
}
**下面显示setLayoutParams的位置-它保持红色并抛出一个错误。无法从静态上下文引用**
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(images[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
ImageView.setLayoutParams(new GridView.LayoutParams(240, 240));
return imageView;
}
}
ImageView.setLayoutParams(新的GridView.LayoutParams(240240))代码>=>imageView.setLayoutParams(新的GridView.LayoutParams(240240))代码>
I=>I
就这些 将ImageView
更改为ImageView
。这里ImageView.setLayoutParams(新的GridView.LayoutParams(240240))代码>谢谢。非常感谢