需要引入
import
android.content.res.Resources;
import
android.content.res.
TypedArray;
obtainStyledAttributes 浸染就是从我们本身界说的attr.xml读取所需信息
public class ImageAdapter extends BaseAdapter
{
int mGalleryItemBackground;
private Context mContext;
private Integer[] myImageIds;
public ImageAdapter(Context c, Integer[] aid)
{
mContext = c;
myImageIds = aid;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
mGalleryItemBackground = a.getResourceId
(
R.styleable.Gallery_android_galleryItemBackground, 0
);
a.recycle();
}
@Override
public int getCount()
{
// TODO Auto-generated method stub
return myImageIds.length;
}
@Override
public Object getItem(int position)
{
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position)
{
// TODO Auto-generated method stub
return position;
}
@Override
public View getView
(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
/*发生ImageView工具*/
ImageView i = new ImageView(mContext);
/*配置图片给imageView工具*/
i.setImageResource(myImageIds[position]);
/*从头配置图片的宽高*/
i.setScaleType(ImageView.ScaleType.FIT_XY);
/*从头配置Layout的宽高*/
i.setLayoutParams(new Gallery.LayoutParams(138, 108));
/*配置Gallery配景图*/
i.setBackgroundResource(mGalleryItemBackground);
/*返回imageView工具*/
return i;
}
}
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/8424.html