IT

클릭 가능한 ImageView와 ImageButton의 차이점

lottoking 2020. 6. 21. 19:09
반응형

클릭 가능한 ImageView와 ImageButton의 차이점


ImageView클릭 가능한 것으로 설정되어있는 사이 ImageButton? 와 비교하여 중요한 차이점이 있는지 궁금 합니다 .

다른 것을 사용하는 이유가 있습니까? 유일한 옵션으로 ImageButton남겨 ImageView지는 드로어 블에 대한 제한이 있습니까?

클릭 가능 광고 ImageView선택하면 버튼의 기능이 손실 될 수 ImageButton있습니까?


기본 스타일을 제외하고는 차이가 없습니다. ImageButton기본적으로 널이 아닌 배경을 갖습니다.

편집 : 또한 ImageButton.onSetAlpha()메소드는 항상 false를 반환하고 scaleType로 설정되며 center항상 초점을 맞출 수 있도록 팽창됩니다.

ImageButton기본 스타일은 다음과 같습니다 .

 <style name="Widget.ImageButton">
     <item name="android:focusable">true</item>
     <item name="android:clickable">true</item>
     <item name="android:scaleType">center</item>
     <item name="android:background">@android:drawable/btn_default</item>
 </style>

ImageButton은 ImageView에서 상속됩니다.

public class ImageButton extends ImageView {
public ImageButton(Context context) {
    this(context, null);
}

public ImageButton(Context context, AttributeSet attrs) {
    this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
}

public ImageButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);
}

@Override
protected boolean onSetAlpha(int alpha) {
    return false;
}

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setClassName(ImageButton.class.getName());
}

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName(ImageButton.class.getName());
}

@ Micheal이 설명 한대로 나는 그의 대답에 세부 사항을 추가합니다.


클릭 할 때 버튼 클릭의 효과는 imagebutton에는 있지만 imageView에는 없습니다.

참고 URL : https://stackoverflow.com/questions/5847136/difference-between-a-clickable-imageview-and-imagebutton

반응형