gpt4 book ai didi

android - Showcaseview 库多次调用 Recyclerview 的第一项

转载 作者:行者123 更新时间:2023-11-30 00:10:29 26 4
gpt4 key购买 nike

我正在使用 https://github.com/florent37/TutoShowcase这个 showcaseview 库在我的代码中。

它在 activityfragment 中工作正常。但是当我调用 recyclerview 项目时,它显示多个弹出窗口并变得停电。

mRecyclerViewList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Logger.log("Call");

TextView textView = (TextView) mRecyclerViewList.getChildAt(0).findViewById(R.id.txt_add_tocart_btn);
Logger.log("Textview" + textView);
textView.setFocusableInTouchMode(true);
TutoShowcase.from((Activity) context).setContentView(R.layout.tuto_showcase_tuto_sample)
.setFitsSystemWindows(true).on(textView).addRoundRect(35).showOnce("1").show();
// unregister listener (this is important)
if (Build.VERSION.SDK_INT < 16) {
mRecyclerViewList.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mRecyclerViewList.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});

如何避免出现多个弹出窗口?

最佳答案

你的问题如何避免多个弹出窗口:

只要设置一个 bool 值就可以避免多次显示。

boolean isShown = false;

mRecyclerViewList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Logger.log("Call");
if(!isShown){
TextView textView = (TextView) mRecyclerViewList.getChildAt(0).findViewById(R.id.txt_add_tocart_btn);
Logger.log("Textview" + textView);
textView.setFocusableInTouchMode(true);
TutoShowcase.from((Activity) context).setContentView(R.layout.tuto_showcase_tuto_sample)
.setFitsSystemWindows(true).on(textView).addRoundRect(35).showOnce("1").show();
isShown = true;
}
// unregister listener (this is important)
if (Build.VERSION.SDK_INT < 16) {
mRecyclerViewList.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
mRecyclerViewList.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});

关于android - Showcaseview 库多次调用 Recyclerview 的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48221051/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com