Animate or scroll EditText to top of screen - android

I have a DialogFragment, where is a ScrollView with some EditText fields. If the user press on the last one, it should be moved to top of the dialog, right under the title.
If I just scroll to this field with scrollView.smoothScrollTo(0, view), it just appears over the soft keyboard, but other fields over this last one are still shown.
If I make the visibility of all fields above "GONE", it works fine, but the user can't scroll back, but I need it.
I don't know if it is possible on Android at all. Can anybody please help me? I spent three days on this problem but could not find the solution. Any help will be appreciated!
EDIT: screenshots
this is what I have:
and what I need:

Related

Get rid of annoying EditText focus

I have a pretty big ScrollView that consists of EditTexts and Spinners.
I have a huge problem with EditText focus that has been driving me nuts for the last 2 days. The issue is:
After editing an EditText, press 'back' to close the keyboard (the EditText) still remains focused, so when I scroll down to a Spinner and pick an item, the ScrollView jumps back to the last focused EditText, which is very annoying.
I've looked all over StackOverflow and tried everything. I've tried clearFocus() on the EditText after editing, but the focus just jumps to another EditText. I put android:focusableInTouchMode="true" and android:focusable="true"on the parent LinearLayout, hoping that it would steal the focus. Still doesn't work.
I have tried setting click listeners on spinners, and calling requestFocus() when clicking them. Nothing works.
Please help.

EditText in RecyclerView causes scroll to jump around

I have an EditText inside a RecyclerView. Whenever I press any key on the keyboard, the RecyclerView scroll jumps around.
At first I thought it might be that the list is constantly updating on every key stroke, but that is not the case. I only update the list items once.
Please don't suggest using adjustPan. Yes, that will solve the problem in portrait, since the list isn't very long, but the problem still occurs on small screens or in landscape mode when the list doesn't fit on screen.
I've also tested with and without nestedScrollingEnabled="false", which didn't help either.
Here's a GIF showing what's happening. In this case I'm just pressing the backspace key over and over again.
What is causing this, and how do I prevent it?

Android EditText click, keyboard scroll to different view

I have an EditText. When I click on it, the input keyboard shows up with the EditText directly above it. I want the keyboard to show up a little bit further down at another View, as if the keyboard is focusing on that. Is there a way to handle this?
My use case is I have two EditTexts and a Button in vertical LinearLayout. I want it so that when I click on either of the EditTexts, the keyboard will popup and still show all three Views.
Best practice, you won't want that, i.e showing all views while the keyboard is showing. This will force android to squeeze the views when there isn't enough space.
Best option is try adding paddingBottom to your EditText an example being android:paddingBottom="15dp" This should align the keyboard 15 pixels below your EditText.
You could also use ScrollView as suggested above which allows android to auto handle vertical scrolling for you.

Leanback.DetailsFragment not scrolling as expected

I have a details fragment that is using a DetailsOverviewRow and FullWidthDetailsOverviewRowPresenter. When the page first loads the action buttons are selected. When I press down once, focus leaves the buttons and nothing else happens. When I press down a second time focus moves to a ListRow that is further down the page. I'm trying to figure out why the overview, or body as it's called in the presenter, section doesn't focus.
Should there not be a second 'state' between the two screenshots where the overview/body is readable?
Possibly of note. The DetailsFragment isn't declared in an activities xml, I'm changing fragments manually using FragmentTransactions. Also, the Fragment is instantiated using a static create method (source below).
Thanks in advance.
Activity xml
DetailsFragment java
I haven't tried this example in particular, but from my time spent with Leanback support library, I learned that even though a lot of helpful stuff is indeed provided, a lot is not :D
So I would try these things:
1) Make sure that something in the area you want visible is focusable. (Clickable elements should be focusable by default, but better check too) What I mean is that on the screenshot, there is just text, no buttons or editable content in that area. So when you press down, there is nothing to focus. What happens if you make the body TextView focusable?
(Yes, one would expect that the support library would take care of that, but that might not be the case.)
2) Find out what actually gets focused when you press down, since as you said, the focus leaves the buttons - but where does it go? (How to find out which view is focused?) You might have a "direction problem" somewhere. That is - the focus travels based on the view hierarchy tree, not based on what we see on the screen. In some cases, it is possible to skip some elements or get stuck somewhere by moving focus through an unexpected part of the view tree, that makes sense for the algorithm, but isn't logical from the human perspective.
The details presenter focus works this way :
1) First focus is given to Action buttons. Right/left nav press shifts the focus right/left between action buttons.
2) Down nav press from actions row shifts the focus from actions row to details row (individual details items itself are not focusable), this is achieved by shifting the Thumbnail anchoring position to further south.
3) Down nav press from details row shifts the focus from details row to related row.
So the details row gains focus by changing the anchoring position of Thumbnail image. Is your thumbnail image changing its anchoring position when pressing down from actions row?
Hate to answer my own question. This was due to my failure to RTFM. I was creating the fragment UI after a network request completes. For the FullWidthDetailsPresenter to work properly it and the ClassPresenterSelector() should be initialized in the fragments onCreate() method.

When do Android EditText's requestFocus()

I have a number of EditTexts inside a scrollview. In the background these fields are linked to a number of other fields and regularly (once a second or so) the layout has it's textfields updated depending on the values in the EditText.
The problem is if one EditText has focus at the top of the ScrollView and the user scrolls the view done (i.e. so the focused EditText is off screen), but if the update is made to the views, the scroll view moves up to focus on the EditText at the top of the view.
The closest I have got to remedying this is to make the scroll view change focus when scrolling however this is still has the same behaviour but at a reduced scale.
Does anyone have an idea of how I can stop this from happening?
Cheers,
Matt
You can try using EditText#setFocusable around your code that updates the value. I haven't tested this but if the problem is that it is getting focus when you use setText() it may help.

Categories

Resources