Stop ScrollView from auto-scrolling to an EditText when using ConstraintLayout - android

I`m have a problem just like this one:
Stop ScrollView from auto-scrolling to an EditText
I have Layout inside a ScrollView. In this layout there`s a lot of diffetent views (EditText, Spinners, etc...)
If a EditText has the focus and then I select a item from a Spinner, the display auto-scroll back to the EditText that have the focus.
Putting this code in the Layout parameters, solves the problem in most cases.
android:focusable="true"
android:focusableInTouchMode="true"
BUT...
My layout is a Constraint Layout and what is happening is that all EditText that have a 0dp ("match_constraint") size, or "match_parent" are still doing the auto-scroll to it. And the EditText that have a fixed size ou "wrap_content" works fine.
"This Layout is inside a ScrollView"
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
"This EditText, if have focus, make the auto-scroll to it"
<EditText
android:id="#+id/edtText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="someView"/>
"This EditText, if have focus, DO NOT make a auto-scroll to it"
<EditText
android:id="#+id/edtText2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="text"
app:layout_constraintTop_toBottomOf="#+id/edtText1"
app:layout_constraintStart_toStartOf="parent"/>
...
...
...
...
"Spinner at the end of Layout that i'm selecting a item..."
<Spinner....
Again... If I'm Using a Linear or Relative layout, the solution works fine... But when using the Constraint layout works for some EditText and others NOT, and the tests that I have made point to the fact that some EditText use a match_constraint size or somthing related to it..
Any one else having this same problem or able to replicate the problem that is happening here only with the Constraint layout ???
Thanks

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.

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.

EditText tab order

I have a layout consisting of a LinearLayout with a vertical orientation containing several EditTexts. The virtual keyboard of each of these EditTexts has a "next" button. Pressing the "next" button moves the cursor to the EditText below it.
However, somewhere in the middle of these EditTexts I added another LinearLayout, this one horizontal, with a few EditTexts inside of it. This leaves me with several EditTexts stacked vertically, then a few EditTexts on 1 row horizontal to each other, and then more EditTexts stacked vertically underneath.
The tab order begins as before, but when it reaches the first EditText of the horizontal LinearLayout, hitting the "next" button doesn't move to the next EditText to its right. It skips the two to the right and moves down to the EditText below.
How can I achieve the tab order I desire?
I've attached an image, a true work of art really, of the order I want
use android:nextFocusDown="your next id edit text". Example :
....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/editText1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:nextFocusDown="#+id/editText2" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
....
Look into using the XML tags nextFocusDown/Forward/etc. Documentation

How Linear Layout get Focus?

I am developing an android application.
I was created an activty that contains several components
on the top it contains spinner,
after that it contains linear layout in which it has two textview,
1 has static value and other is dynamic value that is filled when user click on that linear loyout an dialogbox is created and after setting value on that dialog it fills other textview.
i have 4 linearlayout of this type after that i have another linear layout at the end that contains 2 button.
The problem is that in emulator when i scroll mouse it focus on the spinner and after that the last button(means it color changes to orange)
So the question is that how can i get focus on that 4 linear layout?(i set focusable & focusontouch & clickable value true of that linearlayout.)
I have done this, and setting android:clickable="true" on my LinearLayout did the trick. I just set a click handler for that layout when I set up my views.
From #david-lord's comment, only the parameter
focusableInTouchMode="true"
is necessary, so in XML
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusableInTouchMode="true">
allows the call
linear_layout.requestFocus()
I have a LinearLayout with:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectorbarbutton"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
and this work getting focus and click events correctly.
Please try to set android:focusable=true ,
I am not sure about this but may solve your problem.

Android Show/Hide Widget Resize Fill Parent

I have an EditText with a Button next to it. The button is hidden at first so the EditText takes up the full screen, which is good. When they tap the EditText I have the button appear next to the EditText, and it resizes itself accordingly. However, when I hide the Button (I set visibility to gone), the EditText does NOT resize to full screen (leaving a gap to the right of the EditText). Any tips?
I have tried putting the EditText and Button in both a LinearLayout and a TableLayout (with stretchable column, etc) and I see the same behavior. I also tried doing some runtime calls to removeView/addView stuff and that didnt work. I also tried calling invalidate() on both the EditText and its parent.
Thanks!
I encountered the same question, I want to change the size of an EditText when hiding and showing a Button which stands next to it, but the EditText's size will not shrink after call setVisibility(View.VISIBLE) on the button. I solved it by adding a android:layout_weight="1" to the EditText.
The layout xml looks like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/search_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:id="#+id/hide_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn"
/>
</LinearLayout>

Categories

Resources