android - Scrollview moves focused editText out of view when its numeric right aligned -


i put 5 edittext in linearlayout in horizontalscrollview.

when edittext right aligned , has number inputtype, scrollview scrolls right when edittext got focus, if means edittext go out of view

i did different tests , seems happens when edit text right aligned , input type number.

  • all left aligned, inputtype number : works
  • all right aligned, inputtype default(text): works
  • all right aligned, 1st 1 number: scrolls end
  • all right aligned, inputtype number: scrolls end

the scrollview scrolled left , keyboard hidden, when tap on 1st edittext scrollview scrolls right, hidding edittext focused

behavior

edit : problem occurs on device nexus 7 (2012) 6.0.1 , emulator nexus 7 5.1 , 4.4.2. working fine on device galaxy tab3 4.4.2

if want try, layout

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:minwidth="25px"     android:minheight="25px">     <horizontalscrollview         android:minwidth="25px"         android:minheight="25px"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/contentcontainer"         android:fillviewport="true">         <linearlayout             android:orientation="horizontal"             android:id="@+id/maincontentcontainer"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:focusableintouchmode="false"             android:focusable="false">             <textview                 android:text="test"                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:id="@+id/textview1"                 android:lines="1" />             <edittext                 android:layout_width="250dp"                 android:layout_height="wrap_content"                 android:id="@+id/edittext1"                 android:hint="1"                 android:inputtype="number"                 android:gravity="right" />             <edittext                 android:layout_width="250dp"                 android:layout_height="wrap_content"                 android:id="@+id/edittext2"                 android:hint="2"                 android:inputtype="number"                 android:gravity="right" />             <edittext                 android:layout_width="250dp"                 android:layout_height="wrap_content"                 android:id="@+id/edittext3"                 android:hint="3"                 android:inputtype="number"                 android:gravity="right" />             <edittext                 android:layout_width="250dp"                 android:layout_height="wrap_content"                 android:id="@+id/edittext4"                 android:hint="4"                 android:inputtype="number"                 android:gravity="right" />             <edittext                 android:layout_width="250dp"                 android:layout_height="wrap_content"                 android:id="@+id/edittext5"                 android:hint="5"                 android:inputtype="number"                 android:gravity="right" />         </linearlayout>     </horizontalscrollview> </linearlayout> 

i have been dealing same problem. interestingly problem doesn't occur on android 7.

my solution/workaround (which far perfect) ditch inputtype , instead use keylistener restricted numbers.

in case doing in java , replaced line

setinputtype(inputtype.type_class_number | inputtype.type_number_flag_signed); 

with this

setkeylistener(digitskeylistener.getinstance("0123456789./-‌​")); 

which i'm after without unexpected scrolling


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -