LoadingStateView icon indicating copy to clipboard operation
LoadingStateView copied to clipboard

ViewPager2 Fragment中showContentView 高度异常

Open Zhao-Yan-Yan opened this issue 5 years ago • 10 comments

image

Zhao-Yan-Yan avatar Jul 15 '20 03:07 Zhao-Yan-Yan

QQ截图20200715154043

QQ截图20200715153958

Zhao-Yan-Yan avatar Jul 15 '20 07:07 Zhao-Yan-Yan

viewpager2 的 fragment 根布局的 layoutParams为null

Zhao-Yan-Yan avatar Jul 15 '20 07:07 Zhao-Yan-Yan

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

DylanCaiCoding avatar Jul 16 '20 02:07 DylanCaiCoding

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

确实 那我先用回viewpager也行

Zhao-Yan-Yan avatar Jul 16 '20 03:07 Zhao-Yan-Yan

@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
}

sweet2o09 avatar Oct 15 '20 05:10 sweet2o09

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

Zhao-Yan-Yan avatar Oct 16 '20 10:10 Zhao-Yan-Yan

@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
}
``` 这个管用

wang2793312458 avatar Nov 09 '20 02:11 wang2793312458

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

AlbertZyc avatar Aug 04 '22 02:08 AlbertZyc

解决了吗。。。

AlbertZyc avatar Aug 17 '22 09:08 AlbertZyc