响应tap的片段下的android视图

时间:2016-02-05 05:10:13

标签: android layout fragment

我有两个片段A和B.Fragment A有一个视图,当点击时会打开Fragment B,它占据了activity_main.xml中的框架布局。框架布局最初在其中有一个recyclerview。但是当它只是点击片段B时activity_main.xml中的recyclerview正在响应。

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

1 个答案:

答案 0 :(得分:4)

在片段B的xml中,在根元素上添加

机器人:可点击= “真”

确保布局的高度为match_parent