【问题标题】:android view under fragment responding to tap响应点击的片段下的android视图
【发布时间】:2016-02-05 05:10:13
【问题描述】:

我有两个片段 A 和 B.Fragment A 有一个视图,单击该视图会打开 Fragment B,它占据 activity_main.xml 中的框架布局。框架布局最初有一个 recyclerview。但是当简单地点击 Fragment 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>

【问题讨论】:

    标签: android layout fragment


    【解决方案1】:

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

    android:clickable="true"

    确保布局的高度是 match_parent

    【讨论】:

    • 很好的答案。由于这个问题,我也很困惑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多