2016-02-05 49 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