2016-02-05 44 views
0

我有兩個片段A和B.片段A有一個視圖,當點擊時打開片段B,它佔據了activity_main.xml中的框架佈局。框架佈局最初有一個recyclerview。但是,當簡單地點擊片段B時,activity_main.xml中的recyclerview正在響應。Android下的片段響應水龍頭

片段A:

public class Motels extends Fragment{ 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View v=inflater.inflate(R.layout.motels, container, false); 
     final Toolbar toolbar=(Toolbar) getActivity().findViewById(R.id.toolbar); 
     toolbar.setTitle("Motels"); 
     final FragmentManager fragmentManager = getFragmentManager(); 
RippleView rippleView6=(RippleView) v.findViewById(R.id.ripple6); 
     rippleView6.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() { 

      @Override 
      public void onComplete(RippleView rippleView2) { 
       Log.d("Sample", "Ripple completed"); 


       MotelVaik motelVaik= new MotelVaik(); 
       FragmentManager fragmentManager6=getFragmentManager(); 
       final FragmentTransaction transaction6= fragmentManager.beginTransaction().setCustomAnimations(R.anim.enter_from_left_, R.anim.exit_to_right,R.anim.enter_from_right,R.anim.exit_to_left); 
       transaction6.replace(R.id.frame, motelVaik); 
       transaction6.addToBackStack("vaik").commit(); 
      } 

     });}} 

片段B:

public class MotelVaik extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View v=inflater.inflate(R.layout.motel_vaikkom,container,false); 
    return v;}} 

activity_main.xml中

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main" 
    > 
    <FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="match_parent" 
     android:layout_height="450dp" 
     > 
     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/recyclerview" 
      android:layout_marginTop="5dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:scrollbarStyle="insideOverlay" 
      > 
      </android.support.v7.widget.RecyclerView> 
    </FrameLayout> 
</LinearLayout> 

回答

4

在片段B的XML,在根元素只是添加

android:clickabl e =「true」

確保佈局的高度是match_parent

+0

很好的答案。我也很困惑,由於這個問題 –

+0

答案是正確的,謝謝你... – jobin