gpt4 book ai didi

android - 使用可折叠工具栏和页面适配器时请求布局调用不当

转载 作者:行者123 更新时间:2023-12-05 07:45:38 25 4
gpt4 key购买 nike

我遇到以下错误的无限循环:

W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatTextView{9968cfe V.ED..... ......ID 64,0-1376,301 #7f0c008a app:id/project_name} during layout: running second layout pass
I/ViewRootImpl: requestLayoutDuringLayout is already in process
I/ViewRootImpl: requestLayoutDuringLayout is already in process
I/ViewRootImpl: requestLayoutDuringLayout is already in process

我有一个 CoordinatorLayout,它在 AppBarLayout 中包含一个 CollapsingToolbarLayout。在 AppBarLayout 之外,我有一个 ViewPager。当 CollapsingToolbarLayout 折叠时,上面的错误消息开始无限循环。

CollapsingToolbarLayout 关闭时,我有一个监听器,以便我可以隐藏和显示一些 View 。

@Override public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}

if (scrollRange + verticalOffset == 0 && !isShow) {
view.showToolbarTitle(true);
isShow = true;
} else if (isShow) {
view.showToolbarTitle(false);
isShow = false;
}
}

当我删除此监听器时,错误就会停止。我假设正在发生的事情是 onOffsetChanged(AppBarLayout, int)CollapsingToolbarLayout 折叠时不断被调用。但这没有任何意义,因为没有任何偏移量被更改。有谁知道为什么会发生这种情况?

最佳答案

对于 Kotlin 如果您在此处设置任何 View 的值,它将充满 requestLayout 进程警告。您可以尝试查看可见性 gone/visible

private fun addListener(){
var isShow = false
var scrollRange = -1
tvUserTitle.text = "Hasnine"

ioCoroutineScope.launch {
appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { barLayout, verticalOffset ->


if (scrollRange == -1) {
scrollRange = barLayout?.totalScrollRange!!
}
if (scrollRange + verticalOffset == 0) {
//tvTitleHome.title = "Hasnine"
//toolbarCollapse.title = "hello world"

isShow = true
showTitle(isShow)

} else if (isShow) {
//tvTitleHome.title = "" //careful there should a space between double quote otherwise it wont work

isShow = false
showTitle(isShow)
}
})
}
}

private fun showTitle(show: Boolean){
if(show){
tvUserTitle.visibility = View.VISIBLE
}else{
tvUserTitle.visibility = View.GONE
}
}

关于android - 使用可折叠工具栏和页面适配器时请求布局调用不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41507995/

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