मैं टिप्पणी जोड़ने के लिए विशेषाधिकार नहीं है, तो मैं जवाब के रूप में इस पोस्टिंग कर रहा हूँ। छवियों के बगल में आपका क्या मतलब है? क्या यह उपयोगकर्ता एक छवि पर क्लिक करेगा, इसे इसके आगे की छवि के साथ बदल दिया जाना चाहिए? क्या आप वह कोड भी साझा कर सकते हैं जहां आपने इन छवियों को देखने के लिए पिन किया है या कोई एडाप्टरव्यू देखा है?
संपादित करें:
मैं भी कई बार ऐसी ही स्थिति थी जब पूर्ण लेआउट जीवित थे। इस प्रकार मैं क्या किया था है:
कक्षा:
public class PlayScreen extends Activity implements OnTouchListener
private Panel mainPanel; // Panel for out display
boolean firstClick = false;
OnCreate:
main = new Panel(this);
// Display the panel (calls the ondraw and updates the display)
setContentView(main,new ViewGroup.LayoutParams(screenwidth,screenheight));
// Listen for touchevents on the panel
main.setOnTouchListener(this);
पैनल:
class Panel extends View
{
/*
* Init a Panel to draw on and a paint to paint with
*/
Paint mBitmapPaint;
public Panel(Context context)
{
super(context);
mBitmapPaint = new Paint();
}
@Override
protected void onDraw(Canvas canvas)
{
drawImages(canvas);
}
}
drawImages:
private void drawImages(Canvas canvas)
{
for(int i = 0; i<MAX_ROWS; i++){
for(int j=0; j<MAX_COLS; j++)
{
int xpos = j*bmp.getWidth()+j*2;
int ypos = i*bmp.getHeight()+i*2;
bmp = BitmapFactory.decodeResource(mContext.getResources(), items[i][j],opts);
canvas.drawBitmap(bmp,xpos,ypos,mBitmapPaint);
clickzonex.add(xpos);
clickzoney.add(ypos);
clickzonei.add(i);
clickZonej.add(j);
}
}
}
OnTouch:
onTouch(View v, MotionEvent event) :
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
// imply logic
x = (int) event.getX();
y = (int) event.getY();
for(int i = 0; i < clickzonex.size();i++)
{
if((x>clickzonex[i]) && (x<(clickzonex[i]+ bmp.getwidth())) && (y>(clickzoney[i])) && (y<(clickzoney[i]+bmp.getHeight())))
{
// we have a click in a zone so we get the card-number in that zone
if(firstClick == false)
{
itemAti=clickzonei[i];
itemAtj = clickzonej[i];
firstclick = false;
}
else
{
FirstItemToSwap = items[clickzonei[i]][clickzonej[i]];
SecondItemToSwap = items[itemAti][itemAtj];
// Now do the swaping using any algo you like.
main.postInvalidate();
firstclick = true;
}
break;
}
}
return true;
}
else
{
return false;
}
मैं बस अपना खुद का उदाहरण का उपयोग करें और अपने कोड के साथ मिश्रण आप तर्क को दिखाने के लिए कोशिश की है। मुख्य बिंदु यह है कि ऑनड्रा विधि में केवल ड्रैंकवस को कॉल करें और स्पर्श पर आइटम को स्वैप करें [] [] और पैनल क्लास के पोस्टिनवालिडेट विधि को कॉल करें।
स्रोत
2012-01-03 06:13:04
http://stackoverflow.com/questions/8708324/how-to-swap-the-bitmap-images-on-view-in-android –
कृपया ऊपर के लिंक मैं कोड कार्यान्वयन दे दिया है के माध्यम से जाना। –