문제

just wanted to make a clickable image and I don't know which option will be more efficient. What's better: a button that has a background image or a imageview that is clickable?

도움이 되었습니까?

해결책

Adding clickListener to ImageView is a cleaner way. In the button, you may face issues like, image not being bordered properly. It can be done with changes in xml, but its an overhead.

ImageView imageView = (ImageView) findViewById(R.id.<ImageViewId>);
imageView.setOnClickListener(this);

In the onClick(View view) method, handle the click event.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top