recyclerView中的listview不滚动 [英] listview inside recyclerView dont scroll

查看:85
本文介绍了recyclerView中的listview不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在recyclerview中有一个列表视图,如下所示:

i have a list view inside a recyclerview like this:

和列表视图滚动不适用于此实现.

and scrolling of listview doesnt work on this implementation.

我的目标是当单击按钮时,列表视图切换以显示和隐藏. 主界面位于选项卡的viewpager上

my goal is when clicking on button the listview toggle to show and hide. the main Ui is on viewpager for tab

   public class tabOne extends Fragment {

    RecyclerView myTabRecycler;
    adapterMainList adapter;

    public tabOne() {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.tab_one, container, false);

        myTabRecycler = (RecyclerView) v.findViewById(R.id.tabRC);
        myTabRecycler.setHasFixedSize(true);
        LinearLayoutManager llm = new LinearLayoutManager(G.context);
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        myTabRecycler.setLayoutManager(llm);
        adapter = new adapterMainList(Utiles.getSampleCat());
        myTabRecycler.setAdapter(adapter);
        Utiles.Log(Utiles.getSampleCat().size());
        myTabRecycler.startNestedScroll(2);

        return v;
    }
    }

recyclerView适配器:

the adapter for recyclerView:

 public class adapterMainList extends  RecyclerView.Adapter<adapterMainList.CatViewHolder> {

    private List<retroCategory> cats;

    public adapterMainList(List<retroCategory> catList) {
        this.cats = catList;

    }


    @Override
    public int getItemCount() {
        return cats.size();
    }


    @Override
    public void onBindViewHolder(final CatViewHolder catViewHolder, final int position) {


        final retroCategory cat = cats.get(position);
        Utiles.Log("BindNow");
    }

    @Override
    public CatViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.
                from(viewGroup.getContext()).
                inflate(R.layout.adapter_item_category, viewGroup, false);
        return new CatViewHolder(itemView);
    }

    public static class CatViewHolder extends RecyclerView.ViewHolder {

        protected ListView vList;
        protected ImageView vImg;


        public CatViewHolder(View v) {
            super(v);

            vList = (ListView) v.findViewById(R.id.adapter_item_list);
            vImg = (ImageView) v.findViewById(R.id.adapter_item_img);

        }


    }
    }

项目Ui:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/adapter_item_cat_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right|center_vertical|center_horizontal"
        android:padding="16dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Title"
        android:textColor="@color/black" />

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        app:cardUseCompatPadding="true"
        card_view:cardBackgroundColor="@color/white"
        card_view:cardElevation="4dp">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <Button
                        android:id="@+id/adapter_item_num_session"
                        android:layout_width="0dp"
                        android:layout_weight="1"
                        android:layout_height="wrap_content"
                        android:padding="4dp"
                        android:gravity="left|bottom"
                        android:textColor="@color/colorPrimaryDark" />

                <ImageView
                    android:id="@+id/adapter_item_img"
                    android:layout_width="0dp"
                    android:layout_height="80dp"
                    android:layout_weight="0.3"
                    android:scaleType="fitXY"
                    android:src="@drawable/sherlock" />


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

    <ListView
        android:id="@+id/adapter_item_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="8dp"
        android:paddingRight="8dp">

    </ListView>




</LinearLayout>

,并且在runnig应用程序上,当我想滚动列表视图时,RecyclerView Scrolled代替了它……我该如何解决呢? 谢谢

and on runnig app when i want to scroll the listview, RecyclerView Scrolled instead of that ... how can i fix That?? thanks

对不起,英语不好

推荐答案

不应在另一个可滚动视图中使用一个ListView. 在这种情况下,您将在RecyclerView中使用ListView.

You should not use a ListView inside another scrollable view. In this case you are using a ListView inside a RecyclerView.

使用LinearLayout代替ListView. 像这样:

Use a LinearLayout instead of the ListView. Something like:

public class MyListLayout extends LinearLayout implements
        View.OnClickListener {

    private Adapter list;
    private View.OnClickListener mListener;

    public MyListLayout(Context context) {
        super(context);
    }

    public MyListLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }

    public MyListLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onClick(View v) {
        if (mListener!=null)
            mListener.onClick(v);
    }

    public void setList(Adapter list) {
        this.list = list;

        //Popolute list
        if (this.list!=null){
            for (int i=0;i<this.list.getCount();i++){
                View item= list.getView(i, null,null);
                this.addView(item);
            }
        }

    }

    public void setmListener(View.OnClickListener mListener) {
        this.mListener = mListener;
    }
}

这篇关于recyclerView中的listview不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆