【问题标题】:listview inside recyclerView dont scrollrecyclerView中的listview不滚动
【发布时间】:2016-01-07 21:20:50
【问题描述】:

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

列表视图的滚动在此实现中不起作用。

我的目标是单击按钮时列表视图切换显示和隐藏。 主用户界面在标签的 viewpager 上

   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 的适配器:

 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);

        }


    }
    }

物品界面:

<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>

当我想滚动列表视图时,在运行应用程序上,RecyclerView 滚动而不是那个......我该如何解决这个问题? 谢谢

抱歉英语不好

【问题讨论】:

    标签: android listview android-listview android-recyclerview


    【解决方案1】:

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

    使用 LinearLayout 而不是 ListView。 比如:

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 2023-03-03
      • 1970-01-01
      • 2020-07-09
      • 2018-08-04
      相关资源
      最近更新 更多