recyclerview无法正常显示

时间:2018-02-07 02:56:19

标签: android android-recyclerview

我在运行我的应用程序时遇到问题,那就是我的回收站视图没有像下面那样正确显示,我已经设置了我的卡片视图宽度以匹配父级,但实际上这不显示为匹配父级,我如何解决这个问题? :

enter image description here

基于我的layout.xml,它应该是这样的:

enter image description here

这是我的layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    app:cardCornerRadius="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/kanjiS"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 1" />

        <TextView
            android:id="@+id/kanjiT"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 2" />

        <TextView
            android:id="@+id/desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 3" />
    </LinearLayout>
</android.support.v7.widget.CardView>

这是我的适配器:

public class VocabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
List<VocabMaster> data;

public VocabAdapter(List<VocabMaster> data) {
    this.data = data;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.modelmadul,null );
    return new VH(v);
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    VocabMaster vm = data.get(position);
    VH vh = (VH) holder;

    vh.hanziS.setText(vm.getHanzi_s());
    vh.hanziT.setText(vm.getHanzi_t());
    vh.desc.setText(vm.getPinyin());

}

@Override
public int getItemCount() {
    return (data == null) ? 0 : data.size();
}

private List<VocabMaster>  datas = new ArrayList();
public void setVocoList(List<VocabMaster> list){
    if(list==null) return;
    datas.clear();
    datas.addAll(list);
    notifyDataSetChanged();
}

public class VH extends RecyclerView.ViewHolder {
    TextView hanziS;
    TextView hanziT;
    TextView pinyin;
    TextView desc;
    ImageView sound, share, favorite;
    Context context;
    LinearLayout linearLayout;

    public VH(View itemView) {
        super(itemView);

        hanziS = itemView.findViewById(R.id.kanjiS);
        hanziT = itemView.findViewById(R.id.kanjiT);
        desc = itemView.findViewById(R.id.desc);

    }
  }
}

0 个答案:

没有答案