如何在 FrameLayout 上实现 RecyclerView?

How to implement RecyclerView on a FrameLayout?

我正在学习 RecyclerView 并卡在 activity。我有一个 bottomNavigationView 和 bottomNavigationView 上方的框架布局我想在该 FrameLayout 上显示一个 RecyclerView。我怎样才能做到这一点? 我的程序没有错误,我不知道为什么它不显示 RecyclerView。

This is the xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Bottom_nav">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomnavid"
       />
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomnavid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_nav"
        />
</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#FFEB3B"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/live_matchrecyclerid"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

    <android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    android:padding="5dp"
    app:cardCornerRadius="3dp"
    app:cardElevation="5dp"
    >
    <TextView
        android:id="@+id/cityid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello"
        android:textSize="50sp"
        android:padding="5dp"/>

</android.support.v7.widget.CardView>

This is the myadapter class

 public class Myadapter extends RecyclerView.Adapter<Myviewholder> {
            ArrayList<String> Citynames;
            Context c;
             public Myadapter(ArrayList<String> citynames, Context c) {
            Citynames = citynames;
            this.c = c;
        }
        @NonNull
        @Override
        public Myviewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            View v = LayoutInflater.from(c).inflate(R.layout.cardview,viewGroup,false);
            Myviewholder VH = new Myviewholder(v);
            return VH;
        }
        @Override
        public void onBindViewHolder(@NonNull Myviewholder myviewholder, int i) {
            myviewholder.nametext.setText(Citynames.get(i));
        }
        @Override
        public int getItemCount() {
            return Citynames.size();
        }
    }
    this is my viewholder class 
        public class Myviewholder extends RecyclerView.ViewHolder {

        TextView nametext;

        public Myviewholder(@NonNull View itemView) {
            super(itemView);
            nametext = itemView.findViewById(R.id.cityid);
        }
    }

This is my main class

public class Feature extends Fragment {
       ArrayList<String> Citynames = new ArrayList<>   (Arrays.asList("dhaka","rongpur","bagura",
            "sylhet","vhola","lalmonirhut","khulna","cumillah","rajshahi"));
    public  Feature()
    {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view  = inflater.inflate(R.layout.feature,container,false);

         RecyclerView recyclerView = view.findViewById(R.id.featurerecyclerid);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        Myadapter myadapter = new Myadapter(Citynames,getActivity());
        recyclerView.setAdapter(myadapter);
        return inflater.inflate(R.layout.feature,container,false);
    }
}

我的项目没有显示错误,但没有显示 RecyclerView。

好的,你只需在创建片段视图之前设置你的回收器视图,我在你上一个问题中主要提到了你
在 'onViewCreated' 方法中设置你的 recyler 视图,请参阅我的回答 there.And 不要一次又一次地 post 相同的问题,你也可以编辑你的问题