Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewPager2 Fragment中showContentView 高度异常 #6

Open
Zhao-Yan-Yan opened this issue Jul 15, 2020 · 10 comments
Open

ViewPager2 Fragment中showContentView 高度异常 #6

Zhao-Yan-Yan opened this issue Jul 15, 2020 · 10 comments

Comments

@Zhao-Yan-Yan
Copy link

image

@Zhao-Yan-Yan
Copy link
Author

QQ截图20200715154043

QQ截图20200715153958

@Zhao-Yan-Yan
Copy link
Author

viewpager2 的 fragment 根布局的 layoutParams为null

@DylanCaiCoding
Copy link
Owner

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

@Zhao-Yan-Yan
Copy link
Author

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

确实 那我先用回viewpager也行

@sweet2o09
Copy link

sweet2o09 commented Oct 15, 2020

@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
Copy link
Author

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

@wang2793312458
Copy link

@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
Copy link

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

@AlbertZyc
Copy link

解决了吗。。。

@IdyllicFish
Copy link

还没解决吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants