DylanCaiCoding / LoadingStateView

Decoupling the code of toolbar or loading status view. (深度解耦标题栏,解耦加载中、加载失败、无数据等缺省页,支持两行代码集成到基类)
Apache License 2.0
676 stars 53 forks source link

ViewPager2 Fragment中showContentView 高度异常 #6

Open Zhao-Yan-Yan opened 3 years ago

Zhao-Yan-Yan commented 3 years ago

image

Zhao-Yan-Yan commented 3 years ago

QQ截图20200715154043

QQ截图20200715153958

Zhao-Yan-Yan commented 3 years ago

viewpager2 的 fragment 根布局的 layoutParams为null

DylanCaiCoding commented 3 years ago

测试了下 viewpager2 的适配器继承 FragmentStateAdapter 才触发,继承 RecyclerView.Adapter 没问题。暂时没排查出原因,如果有需要可以先改成后者。

Zhao-Yan-Yan commented 3 years ago

测试了下 viewpager2 的适配器继承 FragmentStateAdapter 才触发,继承 RecyclerView.Adapter 没问题。暂时没排查出原因,如果有需要可以先改成后者。

确实 那我先用回viewpager也行

sweet2o09 commented 3 years ago

@DylanCaiCoding 大佬你看我这样修改行不行

private fun addView(viewType: ViewType) {
    val viewHolder = getViewHolder(viewType)
    val rootView = viewHolder.rootView
    if (rootView.parent != null) {
        (rootView.parent as ViewGroup).removeView(rootView)
    }
    if (viewType == ViewType.CONTENT) {
        //为了解决Fragment中content布局无法撑满全屏
        contentParent.addView(
            rootView,
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
    } else {
        contentParent.addView(rootView)
    }
    currentViewHolder = viewHolder
}
Zhao-Yan-Yan commented 3 years ago

@DylanCaiCoding 好像这样ToolBar部分就被顶没了

wang2793312458 commented 3 years ago

@DylanCaiCoding 大佬你看我这样修改行不行


private fun addView(viewType: ViewType) {
    val viewHolder = getViewHolder(viewType)
    val rootView = viewHolder.rootView
    if (rootView.parent != null) {
        (rootView.parent as ViewGroup).removeView(rootView)
    }
    if (viewType == ViewType.CONTENT) {
        //为了解决Fragment中content布局无法撑满全屏
        contentParent.addView(
            rootView,
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
    } else {
        contentParent.addView(rootView)
    }
    currentViewHolder = viewHolder
}
``` 这个管用
AlbertZyc commented 1 year ago

因为Viewpager2 里面fragment的bind.root.parent为空.........

AlbertZyc commented 1 year ago

解决了吗。。。

IdyllicFish commented 1 year ago

还没解决吗