在你Activity
(或Fragment
),你在哪裏得到關於你的按鈕,我會做類似下面的地方能見度按鈕將被命名爲x
,y
和all
,他們控制將是button1
,button2
四個按鈕, button3
和button4
。
我們需要一種方法,可以告訴我們,如果所有四個按鈕都不可見。爲此,我們需要使用如果Views
可見性設置爲VISIBLE
該方法返回true isShown()
:
private boolean areButtonsInvisible() {
return !button1.isShown() && !button2.isShown() && !button3.isShown() && !button4.isShown();
}
此方法將返回true
當且僅當所有的按鈕都有自己的知名度設置爲GONE
或INVISIBLE
。
然後,我們需要處理三個視圖狀態按鈕的可見度的方法:在x
,y
的OnClickListeners
private void handleViewButtons() {
if(areButtonsInvisible()) {
x.setVisibility(View.VISIBLE);
y.setVisibility(View.VISIBLE);
all.setVisibility(View.VISIBLE);
}
//You can handle other situations here as well. I haven't added any because you haven't stated anything about other scenarios.
}
然後和all
你只需要添加一個調用方法handleViewButtons()
設置完button1
,button2
,button3
和button4
的可見度。