2011-05-01 7 views
119

과 비교하여 클릭 가능하도록 설정된 ImageView 사이에 중요한 차이가 있는지 궁금합니다.클릭 할 수있는 ImageView와 ImageButton의 차이점

다른 하나 이상을 사용해야하는 이유가 있습니까? 유일하게 가능한 옵션으로 ImageView을 남기는 의 드로어 블에 대한 제한이 있습니까?

클릭 버튼 ImageViewImageButton 이상으로 선택하면 버튼의 기능을 잃을 수 있습니까?

답변

136

기본 스타일을 제외하고 차이점은 없습니다. ImageButton에는 기본적으로 null이 아닌 배경이 있습니다.

편집 : 또한, ImageButton.onSetAlpha() 방법은 항상 scaleTypecenter로 설정하고 항상 포커스로 팽창 것, false를 돌려줍니다.

여기 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> 
+0

답장을 보내 주셔서 감사합니다. 코드를 직접 들여다 보았을 때보 다 더 많이 주셨습니다. 아마 2 일 사이의 선택은 사용자 정의없이 사용할 수있는 기본 등록 정보의 양에 달려 있습니다. – yjw

+0

당신을 진심으로 환영합니다! 그래,별로 차이가별로 없으니, 선택은 버튼이 아니라 버튼 사이라고 생각합니다. – Michael

+15

실제로 내 경험에 두 가지의 다른 차이점은 ListView의 셀에 클릭 가능한 버튼을 놓고 클릭 할 수있는 셀 자체를 유지하면서 이미지 뷰를 사용하면 훨씬 편리하다는 것입니다. EditTexts와 ImageButtons는 TextViews와 ImageView가 필요하지 않을 때 touch 이벤트를 소비하는 것 같습니다. –

17

하여 ImageButton이 이미지 뷰

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()); 
} 

에서 상속 난 그냥 그의 대답에 단추의

4

효과를 세부 사항을 추가 설명 @Micheal로 클릭 할 때 imagebutton이 있지만 imageView는 클릭하지 않습니다.

관련 문제