2015-09-07 107 views
0

我做了一個包含3個RecyclerView的片段,1是一個水平的RV工作,但另一個是垂直的不起作用。我無法翻閱它。RecyclerView不會滾動

(圖片鏈接:[http://s15.postimg.org/lc6bxz9ej/so1.png][2]

HomeFragment.java @AfterViews

LinearLayoutManager catLM = new LinearLayoutManager(mContext); 
    mRVcatList.setLayoutManager(catLM); 
    mRVcatList.setAdapter(new CategoryAdapter(initCategories())); 

    LinearLayoutManager hotLM = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false); 
    mRVhotList.setLayoutManager(hotLM); 
    mRVhotList.setAdapter(new HotItemsAdapter(initHotItems())); 

    LinearLayoutManager brandLM = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false); 
    mRVbrandList.setLayoutManager(brandLM); 
    mRVbrandList.setAdapter(new BrandAdapter(initBrands())); 

    mRVbrandList.addOnItemTouchListener(new HotItemClickListener(mContext, new HotItemClickListener.OnItemClickListener() { 
     @Override 
     public void onItemClick(View view, int position) { 
      FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
      transaction.replace(R.id.mFLframe, new ProductListFragment_()); 
      transaction.addToBackStack(null); 
      transaction.commit(); 
     } 
    })); 
    mRVcatList.addOnItemTouchListener(new HotItemClickListener(mContext, new HotItemClickListener.OnItemClickListener() { 
     @Override 
     public void onItemClick(View view, int position) { 
      FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
      transaction.replace(R.id.mFLframe, new CategoryFragment_()); 
      transaction.addToBackStack(null); 
      ((MainActivity) mContext).hideLogo(); 
      transaction.commit(); 
     } 
    })); 
    mRVhotList.addOnItemTouchListener(new HotItemClickListener(mContext, new HotItemClickListener.OnItemClickListener() { 
     @Override 
     public void onItemClick(View view, int position) { 
      FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
      transaction.replace(R.id.mFLframe, new DetailFragment_()); 
      transaction.addToBackStack(null); 
      ((MainActivity) mContext).hideLogo(); 
      transaction.commit(); 
     } 
    })); 

這裏是我的XML文件,

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="fill_parent"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp"> 

    <!--//HOT--> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:id="@+id/mRLtopHot"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hot Items" 
      android:textColor="@color/ColorPrimaryDark" 
      android:paddingLeft="5dp" 
      android:layout_centerVertical="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/mTVhot" 
      android:textSize="@dimen/bebas_medium" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="2dip" 
      android:background="#00B7F6" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" /> 

    </RelativeLayout> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/mRVhotList" 
     android:layout_width="match_parent" 
     android:layout_height="140dp" 
     android:padding="5dp" 
     android:background="#FFFFFF" 
     android:layout_below="@+id/mRLtopHot"/> 

    <!--CAT--> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:background="#FFFFFF" 
     android:layout_marginTop="10dp" 
     android:id="@+id/mRLtopCat" 
     android:layout_below="@+id/mRVhotList" 
     android:layout_centerHorizontal="true"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Categories" 
      android:paddingLeft="5dp" 
      android:textColor="@color/ColorPrimaryDark" 
      android:id="@+id/mTVcat" 
      android:layout_centerVertical="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:clickable="false" 
      android:textSize="@dimen/bebas_medium" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/mIVcatCollapse" 
      android:paddingRight="5dp" 
      android:layout_centerVertical="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

     <View 
      android:id="@+id/view1" 
      android:layout_width="wrap_content" 
      android:layout_height="2dip" 
      android:background="#00B7F6" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" /> 

    </RelativeLayout> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/mRVcatList" 
     android:layout_width="match_parent" 
     android:layout_height="140dp" 
     android:background="#FFFFFF" 
     android:layout_below="@+id/mRLtopCat"/> 

    <!--BRAND--> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:layout_marginTop="10dp" 
     android:id="@+id/mRLtopBrand" 
     android:background="#FFFFFF" 
     android:layout_below="@+id/mRVcatList" 
     android:layout_centerHorizontal="true"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Brands" 
      android:paddingLeft="5dp" 
      android:textSize="@dimen/bebas_medium" 
      android:textColor="@color/ColorPrimaryDark" 
      android:layout_centerVertical="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/mTVbrand" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingRight="5dp" 
      android:id="@+id/mIVbrandCollapse" 
      android:background="@drawable/abc_ic_menu_moreoverflow_mtrl_alpha" 
      android:layout_centerVertical="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="2dip" 
      android:background="#00B7F6" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" /> 

    </RelativeLayout> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/mRVbrandList" 
     android:layout_width="match_parent" 
     android:layout_height="140dp" 
     android:background="#FFFFFF" 
     android:layout_below="@+id/mRLtopBrand" 
     android:layout_centerHorizontal="true"/> 


</RelativeLayout> 

以前,我做了「類別」和「品牌」選項卡關閉,點擊時可以擴展(這只是setVisibility的一個簡單用法),並且RecyclerView(s)確實滾動!但我不再使用該用戶界面。不幸的是,這個問題出現了。

我怎樣才能使垂直RecyclerView的作品?謝謝!

+1

你把recylcerview內滾動視圖的事業滾動 – Pavan

+0

這WIL幫助您http://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working – Pavan

+0

'嵌套可滾動視圖'將始終導致**混亂**。 –

回答