这是我按下的按钮
button7.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent envent) {
// Pants
bp = 7;
pantsi=1;
button7.setPressed(true);
setTab(7);
resetImageBut();
culori[0] = 0xfffaf3e6;
if (getS() == 1) {
culori[1] = 0xffffffff;
culori[2] = 0xff787878;
culori[3] = 0xff2D2D2D;
culori[4] = 0xff164E94;
culori[5] = 0xff00A1E4;
culori[6] = 0xff36B33A;
culori[7] = 0xffFDD50C;
culori[8] = 0xffE91C1C;
culori[9] = 0xffA68F5A;
} else {
culori[1] = 0xffB87CDB;
culori[2] = 0xffF97EB1;
culori[3] = 0xffE91A46;
culori[4] = 0xffFFE35F;
culori[5] = 0xff009E8E;
culori[6] = 0xff2A88D1;
culori[7] = 0xff3D5782;
culori[8] = 0xff2D2D2D;
culori[9] = 0xffffffff;
}
imgb2.getBackground().setColorFilter(culori[1], PorterDuff.Mode.MULTIPLY);
imgb3.getBackground().setColorFilter(culori[2], PorterDuff.Mode.MULTIPLY);
imgb4.getBackground().setColorFilter(culori[3], PorterDuff.Mode.MULTIPLY);
imgb5.getBackground().setColorFilter(culori[4], PorterDuff.Mode.MULTIPLY);
imgb6.getBackground().setColorFilter(culori[5], PorterDuff.Mode.MULTIPLY);
imgb7.getBackground().setColorFilter(culori[6], PorterDuff.Mode.MULTIPLY);
imgb8.getBackground().setColorFilter(culori[7], PorterDuff.Mode.MULTIPLY);
imgb9.getBackground().setColorFilter(culori[8], PorterDuff.Mode.MULTIPLY);
imgb10.getBackground().setColorFilter(culori[9], PorterDuff.Mode.MULTIPLY);
// imgb10.setVisibility(View.GONE);
button3.setPressed(false);
button4.setPressed(false);
button5.setPressed(false);
button6.setPressed(false);
button8.setPressed(false);
button9.setPressed(false);
setColor(culori[0]);
if(getS()==1){
cbottomm=culori[0];
}else if(getS()==2){
cbottomf=culori[0];
}
adapterPants.notifyDataSetChanged();
gridview.setAdapter(adapterPants);
mGLView.invalidate();
gridview.smoothScrollBy(5000, 500);
return true;
}
});
这会通知我的图像适配器:
public class ImageAdapterShoes extends BaseAdapter {
private Context mContext;
public ImageAdapterShoes(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds8.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setAdjustViewBounds(true);
imageView.setMaxWidth(20);
imageView.setMaxHeight(100);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(10,10,10,10);
// if (!Project.noFilter)
// imageView.setColorFilter(Project.getColor(), Mode.MULTIPLY);
} else {
imageView = (ImageView) convertView;
}
if(Project.getS()==2){
imageView.setImageResource(mThumbIds8[position]);
}else if(Project.getS()==1){
imageView.setImageResource(mThumbIds8m[position]);
}
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
if (Project.getS()==1){
switch(position)
{
case 0:
bmap=SquareShoes.repleceIntervalColor(bmap, 60, 205, 140, 225, 195, 240,Project.cshoesm);
break;
case 1:
bmap=SquareShoes.repleceIntervalColor(bmap, 60, 70, 60, 70, 60, 70,Project.cshoesm);
break;
case 2:
bmap=SquareShoes.repleceIntervalColor(bmap, 155, 205, 75, 170, 35, 150,Project.cshoesm);
break;
case 3:
bmap=SquareShoes.repleceIntervalColor(bmap, 185, 240, 35, 80, 35, 50,Project.cshoesm);
break;
case 4:
bmap=SquareShoes.repleceIntervalColor(bmap, 200, 235, 30, 40, 30, 45,Project.cshoesm);
break;
case 5:
bmap=SquareShoes.repleceIntervalColor(bmap, 170, 210, 200, 240, 210, 255,Project.cshoesm);
break;
case 6:
bmap=SquareShoes.repleceIntervalColor(bmap, 240, 255, 40, 60, 40, 60,Project.cshoesm);
break;
case 7:
bmap=SquareShoes.repleceIntervalColor(bmap, 245, 255, 165, 180, 40, 60,Project.cshoesm);
break;
case 8:
bmap=SquareShoes.repleceIntervalColor(bmap, 130, 145, 120, 135, 110, 125,Project.cshoesm);
break;
case 9:
bmap=SquareShoes.repleceIntervalColor(bmap, 110, 130, 30, 45, 0, 10,Project.cshoesm);
break;
case 10:
bmap=SquareShoes.repleceIntervalColor(bmap, 160, 180, 80, 100, 40, 60,Project.cshoesm);
break;
case 11:
bmap=SquareShoes.repleceIntervalColor(bmap, 220, 235, 30, 45, 30, 50,Project.cshoesm);
break;
case 12:
bmap=SquareShoes.repleceIntervalColor(bmap, 250, 255, 250, 255, 250, 255,Project.cshoesm);
break;
case 13:
bmap=SquareShoes.repleceIntervalColor(bmap, 85, 100, 85, 100, 85, 100,Project.cshoesm);
break;
}
if (Project.getS()==2){
switch (position) {
case 0:
bmap = SquareShoes.repleceIntervalColor(bmap, 145, 160, 205,
220, 140, 155, Project.cshoesf);
break;
case 1:
bmap = SquareShoes.repleceIntervalColor(bmap, 60, 70, 60, 70,
60, 70, Project.cshoesf);
break;
case 2:
bmap = SquareShoes.repleceIntervalColor(bmap, 245, 255, 205,
220, 40, 60, Project.cshoesf);
break;
case 3:
bmap = SquareShoes.repleceIntervalColor(bmap, 230, 255, 130,
210, 170, 230, Project.cshoesf);
break;
case 4:
bmap = SquareShoes.repleceIntervalColor(bmap, 215, 230, 210,
230, 195, 210, Project.cshoesf);
break;
case 5:
bmap = SquareShoes.repleceIntervalColor(bmap, 245, 255, 240,
255, 190, 205, Project.cshoesf);
break;
case 6:
bmap = SquareShoes.repleceIntervalColor(bmap, 250, 255, 125,
140, 40, 55, Project.cshoesf);
break;
case 7:
bmap = SquareShoes.repleceIntervalColor(bmap, 135, 150, 125,
140, 110, 130, Project.cshoesf);
break;
case 8:
bmap = SquareShoes.repleceIntervalColor(bmap, 170, 190, 215,
230, 220, 235, Project.cshoesf);
break;
case 9:
bmap = SquareShoes.repleceIntervalColor(bmap, 235, 250, 165,
180, 190, 205, Project.cshoesf);
break;
case 10:
bmap = SquareShoes.repleceIntervalColor(bmap, 235, 250, 145,
160, 185, 200, Project.cshoesf);
break;
case 11:
bmap = SquareShoes.repleceIntervalColor(bmap, 205, 250, 205,
250, 200, 245, Project.cshoesf);
break;
case 12:
bmap = SquareShoes.repleceIntervalColor(bmap, 75, 170, 35, 130,
20, 90, Project.cshoesf);
break;
case 13:
bmap = SquareShoes.repleceIntervalColor(bmap, 240, 255, 240,
255, 240, 255, Project.cshoesf);
}
}
imageView.setImageBitmap(bmap);
return imageView;
}
// references to our images
private Integer[] mThumbIds8 = {
R.drawable.girl_shoes_01,R.drawable.girl_shoes_02,
R.drawable.girl_shoes_03,R.drawable.girl_shoes_04,
R.drawable.girl_shoes_05,R.drawable.girl_shoes_06,
R.drawable.girl_shoes_07,R.drawable.girl_shoes_08,
R.drawable.girl_shoes_09,R.drawable.girl_shoes_10,
R.drawable.girl_shoes_11,R.drawable.girl_shoes_12,
R.drawable.girl_shoes_13,R.drawable.girl_shoes_14,
};
private Integer[] mThumbIds8m = {
R.drawable.boy_shoes_01,R.drawable.boy_shoes_02,
R.drawable.boy_shoes_03,R.drawable.boy_shoes_04,
R.drawable.boy_shoes_05,R.drawable.boy_shoes_06,
R.drawable.boy_shoes_07,R.drawable.boy_shoes_08,
R.drawable.boy_shoes_09,R.drawable.boy_shoes_10,
R.drawable.boy_shoes_11,R.drawable.boy_shoes_12,
R.drawable.boy_shoes_13,R.drawable.boy_shoes_14,
};
}
SquareShoes 是我用来在 OpenGL 中创建一个正方形来为我的 SurfaceView(不在 Gridview 中)加载纹理的类 SquareShoes 中的 repleceIntervalColor 函数是:
public static Bitmap repleceIntervalColor(Bitmap bitmap,int redStart,int redEnd,int greenStart, int greenEnd,int blueStart, int blueEnd,int colorNew) {
if (bitmap != null) {
int picw = bitmap.getWidth();
int pich = bitmap.getHeight();
int[] pix = new int[picw * pich];
bitmap.getPixels(pix, 0, picw, 0, 0, picw, pich);
for (int y = 0; y < pich; y++) {
for (int x = 0; x < picw; x++) {
int index = y * picw + x;
if (Project.shoesi==0)
if (Color.alpha(pix[index])!=0)
if (
((Color.red(pix[index]) >= redStart)&&(Color.red(pix[index]) <= redEnd))&&
((Color.green(pix[index]) >= greenStart)&&(Color.green(pix[index]) <= greenEnd))&&
((Color.blue(pix[index]) >= blueStart)&&(Color.blue(pix[index]) <= blueEnd))
){
pix[index] = colorNew;
}
}
}
Bitmap bm = Bitmap.createBitmap(pix, picw, pich,Bitmap.Config.ARGB_8888);
return bm;
}
return null;
}
正如我所说,这个程序在 gridview 中加载了一些对象,但有些对象从一开始就没有出现,你必须向下和向上滚动才能使它们出现。我能做什么?