图像按钮的可见性在Lollipop设备及以上版本中不起作用。

3
我有一个默认情况下是不可见的ImageButton
  <ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/anchor"
    android:src="@drawable/anchor"
    android:elevation="6dp"
    android:layout_below="@+id/rl_row_progress_bar"
    android:layout_centerHorizontal="true"
    android:visibility="invisible"/>

在活动中,我使用以下代码更改其属性:
 if(lastPotition == 1){
    mImageButton.setVisibility(View.GONE);
 } else{
    mImageButton.setVisibility(View.VISIBLE);
 }

问题在于,在Android 5.0以下版本中,图像按钮可以正常使用,但在API 21和22中却无法使用。

这是ImageButton的声明:

private ImageButton mImageButton;
mImageButton =(ImageButton)v.findViewById(R.id.anchor); //anchor

感谢您的帮助。

你是否已经设置断点来验证你是否正确地设置了 imageButton 的可见性? - Mikhail
最终我找到了问题所在,因为我没有棒棒糖设备,所以我使用模拟器,并且可见性检查在 if (scrollState == SCROLL_STATE_IDLE) 内部。因此,由于我有一只鼠标并且我使用鼠标的滚动按钮,滚动状态不起作用,但是如果我像触摸屏幕一样使用鼠标滚动我的列表视图,它就可以工作了。 - VasFou
1个回答

0

我曾经遇到过这个问题,但后来发现这与棒棒糖设备中的设置有关。

以下是三个选项的描述: Lollipop Notification setVisibility() Does Not Work?

  • 显示所有通知内容会使所有通知(无论可见性如何)变得公开。

  • 隐藏敏感通知内容会尊重新的可见性类型。

  • 根本不显示通知将使所有通知变得保密。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接