Change source image for image view when pressed

前端 未结 16 564
闹比i
闹比i 2020-12-08 19:53

I have a scroll view with lots of image buttons. I want to change the image for an image button when it\'s pressed. The thing is that I want the image to remain until anothe

16条回答
  •  一生所求
    2020-12-08 20:29

    if u have already a button in ur app that will do the swap between the two pics u have when its clicked then there is a simple Code :D

    // to add Images in android we simply " Copy them from their location and past in (res --> drawable)"

    // then drag and drop "ImageView" and select the image u want to display

    // u can adjust the scale throw "scaleType , layout_Width & layout_Height"

    public boolean swap = true;
    
    public  void change(View view)
    {
        ImageView i = (ImageView) findViewById(R.id.img);
        if (swap)
        {
            i.setImageResource(R.drawable.images);
            swap=false;
        }
        else
        {
            swap=true;
            i.setImageResource(R.drawable.couple);
        }
    
    }
    

提交回复
热议问题