2015-06-15 75 views
4

我是新的Android開發,我正在與android棒棒糖設備中的CoordinatorLayout,問題是 我有一個recyclerview水平滾動摺疊滾動回滾視圖與垂直滾動效果。 如果我不滾動水平回滾視圖,如果我滾動水平滾動視圖一旦它不崩潰,它工作良好。Horizo​​ntalRecyclerView裏面CoordinatorLayout

我的代碼是 activity_main.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.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="160dp" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">  

      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/collapsing_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       app:contentScrim="?attr/colorPrimary" 
       app:expandedTitleMarginEnd="64dp" 
       app:expandedTitleMarginStart="48dp" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

       <android.support.v7.widget.RecyclerView 
        android:id="@+id/recommendedFoodItemsHolder_part1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:layout_collapseMode="parallax" /> 

      </android.support.design.widget.CollapsingToolbarLayout> 
     </android.support.design.widget.AppBarLayout> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recommendedFoodItemsHolder" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
    </android.support.design.widget.CoordinatorLayout> 

</LinearLayout> 

我MainActivity.java是

package in.venkatesh.www.testapp2; 

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.support.v7.widget.Toolbar; 


public class MainActivity extends AppCompatActivity { 

    private RecyclerView mSimpleRecyclerView, recommendedRecyclerView; 
    // private RecyclerView.Adapter mAdapter; 
    private RecyclerView.LayoutManager mLayoutManager,recommendedLayoutManager; 

    private String[] mRecyclerViewValues = 
      new String[]{"Apple Pie", "Banana Bread", "Cupcake", "Donut", "Eclair", "Froyo", 
        "Gingerbread", "Honeycomb", "Ice Cream Sandwich", "Jelly Bean", "KitKat", 
        "Lollipop", "M preview"}; 
    private String[] mRecommendedFoodItems = new String[]{"Chicken Biryani",  "Mutton Biryani", "Veg Biryani","Veg Fried Rice"}; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     // Actionbar 
     final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     // Link the views 
     mSimpleRecyclerView = (RecyclerView) findViewById(R.id.recommendedFoodItemsHolder); 
     recommendedRecyclerView = (RecyclerView) findViewById(R.id.recommendedFoodItemsHolder_part1); 

     // Use this setting to improve performance if you know that changes 
     // in content do not change the layout size of the RecyclerView 
     mSimpleRecyclerView.setHasFixedSize(true); 

     // Use a linear layout manager 
     mLayoutManager = new LinearLayoutManager(this); 
     recommendedLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false); 

     mSimpleRecyclerView.setLayoutManager(mLayoutManager); 
     recommendedRecyclerView.setLayoutManager(recommendedLayoutManager); 


     SimpleRecyclerViewAdapter mSimpleRecyclerViewAdapter = new  SimpleRecyclerViewAdapter(mRecyclerViewValues); 
     SimpleRecyclerViewAdapter recommendedFoodRecyclerViewAdapter = new SimpleRecyclerViewAdapter(mRecommendedFoodItems); 
     mSimpleRecyclerView.setAdapter(mSimpleRecyclerViewAdapter);     recommendedRecyclerView.setAdapter(recommendedFoodRecyclerViewAdapter); 
    } 
} 

回答

8

嘗試使用recycler.setNestedScrollingEnabled(假);這將解決您的問題

+0

OMG !!!非常感謝!我有一個RecyclerView裏面的RecyclerView,這解決了我的問題(工具欄做了奇怪的事情)。我在內部(水平)RecyclerView中調用了'setNestedScrollingEnabled(false)'。 –

+0

@Cortez你能告訴我理由嗎。我很想知道 – eager

+0

非常感謝(y) –

相關問題