Hide floating action button - android

Update: I have solved this problem just by listen to the scroll change event of the NestedScrollView and do the appropriate handling there.
I'm following this tutorial to animate showing and hiding of my FloatingActionButton. But it doesn't really work for my layout. My layout is like this picture:
It has a NestedScrollView and a number of RecyclerView inside. When I scroll by touching the area of NestedScrollView, the FloatingActionButton is animated as expected. But when I scroll by touching the area of one of the RecyclerViews, the FloatingActionButton don't animate at all. When I try debug my code, I realize that the onNestedScroll method doesn't gets called when I scroll by touching on the area of RecyclerView.

Comment out or delete this code block from your xml layout
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_done"
app:layout_anchor="#id/viewA"
app:layout_anchorGravity="bottom|right|end"/>

Related

How to move focus from RowsSupportFragment's row to next layout component?

I am using Android Leanback library for creating TV application. I have a layout which inflates Fragment (which is RowsSupportFragment) and below that there is button. So, when I scroll down to list of items in RowsSupportFragment after reaching to last item focus doesn't goes to button.
I already have tried setting focusable(true), nextFocusDown(buttonId) etc.
I can see that RowsSupportFragment uses VerticalGridView internally to inflate list of items.
Do anybody has any idea about it?
here is my layout:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/listviewFragmentId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:nextFocusDown="#id/nextButtonId"
android:nextFocusForward="#id/nextButtonId"
layout_constraintBottom_toTopOf="#id/nextButtonId"/>
<Button
android:id="#+id/nextButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:focusable="true"
android:text="Hello Next"/>
<// other items>
</android.support.constraint.ConstraintLayout>
Note:
Focus works correctly if I left/right align button.
In My case this was work when i need focus on the any views
view.requestFocus();
In My case,i need focus on the any views on right outside of RowSupportFragment item so Working around with focusOutEnd,focusOutFront and other focus features in the Leanback Style solved my solution.
like for requesting the focus to outside Button widget from RowSupportFragment, setting <item name="focusOutEnd">true</item> in style worked for me.

BottomSheet: issue with nested scrolling (RecyclerView & NestedScrollView)

I have a rather complex BottomSheetLayout which layout is as follow
The root view of my bottom sheet is a custom FrameLayout that allows to round it's corner (both background and children). Nothing else (nothing touch-related)
Then, I use the usual ConstraintLayout in order to layout my Bottom sheet.
This ConstraintLayout contains, amongst other views, a vertical RecyclerView:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<!-- other views -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/events"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="74dp"
app:layout_constraintTop_toBottomOf="#+id/days"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#{viewModel.colors.defaultBackgroundColor}"
tools:background="#ECF0F3"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="#layout/event_item"
tools:itemCount="10" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have no particular issue while dragging my bottom sheet, however, when fully expanded I was expecting the be able to scroll the content of my RecyclerView. But I cannot.
After a lot of researches, I managed to make it scroll by enabling scrolling when my Fragment's view is inflated :
ViewCompat.setNestedScrollingEnabled(this.binding.bottomSheetEvents.getRoot(), true);
However, doing so has a weird consequence. When my bottom sheet's state is EXPANDED, I can finally scroll my RecyclerView, but then there is absolutely no way to drag my Bottom sheet any more : it remains fully expanded.
I have tried a few other ways.
I have tried wrapping my NestedScrollView. In past experience I was able to have the full content of my bottom sheet scrollable thanks to NestedScrollView, but in this case, I only want to scroll my RecyclerView. What ever is above it must remain idle.
I have tired this.binding.bottomSheetEvents.events.setNestedScrollingEnabled(false); but there is no difference.
My belief is that when the bottom sheet is fully expanded, it dispatches scroll events to inner children that can supports its. And, backwards, it knows, at some point, when uses wishes to collapse said bottom sheet. So I guess, something wrong must be happening there.
Further informations:
this bottomsheet is included in my fragment which roots view is a CoordinatorLayout obviously.
the fragment is also hosted in CoordinatorLayout with an AppBar
the include layout uses the app:layout_behavior="#string/bottom_sheet_behavior"
and the include layout also uses behavior_fitToContents set to false so that I can use method setExpandedOffset to prevent the bottom sheet to reach the top.
Version used : 1.1.0-alpha07
Thanks for the help!

First click on a View is not working in Android

I have a LinearLayout which needs to be clickable inside a NestedScrollView inside a CoordinatorLayout and almost all the time the first time I click it it simply doesn't work, I must click it another time.
Clickable LinearLayout:
<LinearLayout
android:id="#+id/qr_code_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
tools:ignore="UseCompoundDrawables">
This is the NestedScrollView container where
the clickable item resides.
EDIT: Okay this is very weird, if I wait some seconds before trying to click the View, it works the first time. It only fails if I click it just after scrolling to the bottom.
I had the same problem. Inside the NestedScollView there was a RelativeLayout element needed to be clicked. As long I didn't scroll to the very bottom, the element could be clicked with a single click. If I would reach the bottom I needed two clicks, except if I waited a number of seconds.
The problem proved to be on the default layout_behavior of the AppBarLayout. I used the custom one suggested in the post below and the problem was solved.
onClick method not working properly after NestedScrollView scrolled

How to position a view off-screen in Android layout

I'm using the Scene/Transition system introduced in 4.4 to simply move an image view from the left to the center of the screen. So the layout for my first scene requires the image to be off screen. I tried android:layout_marginRight but that no effect. What is the correct way to do this?
Use the property translationX or translationY with a negative value. This property sets the horizontal/vertical location of this view relative to its left/top position. You will not see the view off screen in the preview. Run your app and the view must be hidden.
Example:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_margin="16dp"
android:translationX="-72dp"/>
</FrameLayout>
And then in the activity or fragment simply invoke the animate() function.
FloatingActionButton button = (FloatingActionButton)findViewById(R.id.button);
button.animate().translationX(0);
Was thinking one could make the image be to the right of something that is already at the right side, that should keep it off screen. Also, potentially just make it "gone" and then on transtion make it appear.

How to click a view that is behind a scrollview

I have to an EditText behind a ScrollView
I cannot click the EditText anymore. The ScrollView is intercepting it I think. I tried the code below but it doesn't fix it.
Any suggestions?
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:layout_alignParentTop="true" >
Things to try:
The parent view can influence the position of the views. For example
in a FrameLayout all of the views get stacked in the order they are
placed in the layout file (so your issue could be fixed by
rearranging the order of the EditText in relation to the
ScrollView).
You might try to call editText.bringToFront() to force the
EditText in front of the ScrollView.
If you disable the touch-based listeners (OnClickListeners, etc) on
the ScrollView or the container it's in then the action should "pass
through" the ScrollView and allow you to interact with the EditText
behind it. I found this out the hard way when I was trying to make
the opposite scenario work for me (I wanted the top level view to
consume the actions and not fall through to the view behind it).
These solutions worked for me in the past in different scenarios.
In my case I replaced android:layout_height="match_parent" to android:layout_height="wrap_content" and views inside ScrollView become clickable. Hope this helps.
My code:
v<ScrollView
android:layout_width="match_parent"
android:layout_height="WRAP_CONTENT"
android:id="#+id/svTabActions">
<View>...</View>
</ScrollView>
Try placing the editText inside the scrollView.

Categories

Resources