我想在点击屏幕

时间:2017-11-17 11:34:49

标签: android

这是底视图中添加的一个框架布局。如果用户点击屏幕上的任何位置enter image description here

,我想隐藏

我试图让父布局和触摸监听器设置visiblity GONE但触摸列表器不起作用。我的代码是。 查看rootView = getWindow()。getDecorView()。getRootView();

    rootView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                // show-hide view here

                contentSubTableList.setVisibility(View.GONE);

                AppUtility.showToast(PhoneBaseActivity.this, "On touch listner");

                return true;
            }

            contentSubTableList.setVisibility(View.GONE);

            AppUtility.showToast(PhoneBaseActivity.this, "On touch listner");
            return true;
        }
    });

    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


        }
    });

    llParentView = (LinearLayout) findViewById(R.id.llParentView);
    llParentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                // show-hide view here

                contentSubTableList.setVisibility(View.GONE);

                AppUtility.showToast(PhoneBaseActivity.this, "On touch listner");

                return true;
            }


            contentSubTableList.setVisibility(View.GONE);

            AppUtility.showToast(PhoneBaseActivity.this, "On touch listner");

            return true;
        }
    });

请任何人帮助我。

3 个答案:

答案 0 :(得分:1)

片段的父视图布局上的

setOnClickListener()

答案 1 :(得分:1)

您可以使用此方法隐藏和显示片段

public void showHideFragment(final Fragment fragment){

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(android.R.animator.fade_in,
                    android.R.animator.fade_out);

    if (fragment.isHidden()) {
        ft.show(fragment);
        Log.d("hidden","Show");
    } else {
        ft.hide(fragment);
        Log.d("Shown","Hide");                        
    }

    ft.commit();
}

答案 2 :(得分:1)

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llParentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">


<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:maxWidth="@dimen/_50sdp"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="@dimen/_50sdp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:maxWidth="@dimen/_50sdp">


        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/transparent">

            <RelativeLayout
                android:layout_width="@dimen/_50sdp"
                android:layout_height="match_parent"
                android:background="@color/black">


                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginLeft="@dimen/_minus2sdp"
                    android:layout_marginTop="@dimen/_30sdp"
                    android:src="@drawable/ic_whitetable" />


                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rvTableList"
                    android:layout_width="@dimen/_40sdp"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_marginTop="@dimen/_60sdp"
                    android:background="@color/black" />

            </RelativeLayout>


        </RelativeLayout>


    </android.support.design.widget.NavigationView>


</android.support.v4.widget.DrawerLayout>

<FrameLayout
    android:id="@+id/content_bottom"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvSubTable"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_40sdp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom"
        android:layout_marginLeft="@dimen/_50sdp"
        android:background="@color/black"
        android:clipToPadding="false"
        android:orientation="horizontal"
        android:paddingLeft="1dp"
        android:paddingRight="1dp"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager">

    </android.support.v7.widget.RecyclerView>


</FrameLayout>