如题说述,在写一个Dialog弹窗的时候,弹窗中有一个RecyclerView,可是item中的xml布局是match_parent,弹出来后宽度没能铺满整个Dialog。

如果你使用的是原始的RecyclerView可以尝试着使用这方法解决看看,在onCreateViewHolder中把父view丢进去。

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_group_list, parent, false);//解决宽度不能铺满
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        View itemView = View.inflate(context,R.layout.item_recycle,null);
//        return new ViewHolder(itemView);
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_group_list, parent, false);//解决宽度不能铺满
        ViewHolder holder = new ViewHolder(view);
        return holder;

可是我用的是 BaseQuickAdapter——RecyclerView通用适配器使用,这是比较有名的Adapter适配方案,按道理不应该存在上诉方法1的Bug,后来网上一波乱搜,还真搜到了一个解决方案,即:在你的Dialog的xml中,RecyclerView外在包一层父View,这样就能解决问题,我就这么解决的。

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/dialog_list"
            android:layout_width="match_parent"
            android:layout_height="400dp" />
    </RelativeLayout>

原来是LinearLayout下,一堆View从上到下排下去,RecyclerView在最下面,后来用一个RelativeLayout包裹它,直接就可以了,这里要记录一下,这个问题之前居然没有遇到过。

问题描述 如题说述,在写一个Dialog弹窗的时候,弹窗中有一个RecyclerView,可是item中的xml布局是match_parent,弹出来后宽度没能铺满整个Dialog。解决办法方法1如果你使用的是原始的RecyclerView可以尝试着使用这方法解决看看,在onCreateViewHolder中把父view丢进去。View view = Layou... has no installation candidate E: Unable to locate package docker-ce-cli E: Unable to locate package containerd.io -E: Couldn't find any package by glob containerd. io' E: Couldn't find any package by regex containerd. io 这该怎么弄啊 求助求助 Ubuntu 20.04 安装 docker 详解 海上釣鳌客: 安装相应的apt依赖报错: Errors were encountered while processing: /tmp/apt-dpkg-install-s9IkxV/0-ubuntu-advantage-tools_27.13.6~22.04.1_amd64.deb /tmp/apt-dpkg-install-s9IkxV/2-software-properties-common_0.99.22.6_all.deb /tmp/apt-dpkg-install-s9IkxV/3-software-properties-gtk_0.99.22.6_all.deb /tmp/apt-dpkg-install-s9IkxV/4-python3-software-properties_0.99.22.6_all.deb ubuntu 20.04 安装 微信最新方式 Hebackhome: 请问安装后输入什么命令开启微信,桌面没有快捷方式