我最近使用ImageButtons,我遇到了这种新型的ImageButton'VisibilityAwareImageButton'.如果有人能告诉我这个ImageButton的用法以及它与常规的ImageButton有什么不同,那将会非常有用?提前致谢 :)
这是完整的来源VisibilityAwareImageButton
.
class VisibilityAwareImageButton extends ImageButton { private int mUserSetVisibility; public VisibilityAwareImageButton(Context context) { this(context, null); } public VisibilityAwareImageButton(Context context, AttributeSet attrs) { this(context, attrs, 0); } public VisibilityAwareImageButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mUserSetVisibility = getVisibility(); } @Override public void setVisibility(int visibility) { internalSetVisibility(visibility, true); } final void internalSetVisibility(int visibility, boolean fromUser) { super.setVisibility(visibility); if (fromUser) { mUserSetVisibility = visibility; } } final int getUserSetVisibility() { return mUserSetVisibility; } }
它似乎与常规几乎完全相同ImageButton
,只是它跟踪用户实际设置的最后一次可见性.我能找到的唯一用法是在FloatingActionButton
源代码中.它用于跟踪用户想要查看视图的内容,同时执行自己的内部更改和动画.即
if (child.getUserSetVisibility() != VISIBLE) { // The view isn't set to be visible so skip changing it's visibility return false; }
它位于设计支持库中并具有包可见性,因此Google似乎打算在内部使用它(此时似乎仅用于FAB实现).