Reputation: 195
Here is one frame layout added in bottom view. i want to hide if user click on any place on the screen
i have tried to get parent layout and on that touch listener set visiblity GONE but on touch listner is not working. here my code is. View 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;
}
});
please any one help me in that.
Upvotes: 0
Views: 612
Reputation: 363
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>
Upvotes: 1
Reputation: 131
you can use this method for hide and show fragment
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();
}
Upvotes: 1