Change source image for image view when pressed

前端 未结 16 594
闹比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:48

    float alpha_first = 0.2f;
    float alpha_second = 1.0f;
        AlphaAnimation alphadp = new AlphaAnimation(alpha_second, alpha_first);
            switch (v.getId()) {
            case R.id.disable_deactivate_pic:
            ImageButton disable_button =(ImageButton)findViewById(R.id.disable_deactivate_pic);
                    if (!flag) {
                        disable_button.setImageResource(R.drawable.enable_active);
    
                        linearLayout_for_picture = (LinearLayout) findViewById(R.id.linearlayout_imageView_pic);
    
                    alphadp.setFillAfter(true);
                    linearLayout_for_picture.startAnimation(alphadp);
                    flag=true;
                    }
            else {
                        disable_button.setImageResource(R.drawable.disable_active);
                        alphadp.setFillAfter(false);
                        linearLayout_for_picture.startAnimation(alphadp);
                        flag=false;
                    }
    
                break;
    

提交回复
热议问题