Android Scrollview and Keyboard not working correctly with Absolute layout as Root...

Using Forms 1.3.0 at the moment...

OK I have a special hierarchy in my project and stacks and need the keyboard to activate the scroll view correctly however in Android there seems to be a bug because the same code on the iOS side is working correctly... Here is the layout I have...

(NOT WORKING)
ContentPage
--- AbsoluteLayout
----- StackLayout (this is my custom header)
----- StackLayout (this is my custom sidenav)
----- StackLayout (this is my custom content area)
------- ScrollView
--------- StackLayout
----------- Entry (input)
----------- ...... more inputs

Activating an Entry box will bring up the keyboard but will not scroll the scrollview to the correct location so the keyboard does not block the input... I don't want to be using the traditional layout of a current navigation layout and navigation bar because it very limiting in the type of layout I am trying to make...

The above layout and code works perfectly on iOS but not on Android... When the keyboard pops up it does NOT scroll the view correctly... However the below layout does work on Android but it does not let me build the type of layout that I want...

(WORKING)

  • ContentPage
    --- StackLayout
    ----- StackLayout (this is my custom header)
    ----- StackLayout (this is my custom content area)
    ------- ScrollView
    --------- StackLayout
    ----------- Entry (input)
    ----------- ...... more inputs

Any ideas? or maybe I wait for Forms 1.3.2 ???

I need to have an AbsoluteLayout on the very top so I can position all my layout element accordingly... (nav bar, side nav, satellite buttons, etc...) It is just not achievable using a StackLayout on the Root... Unless someone knows how...

Thanks,

Posts

  • AndrewVoganAndrewVogan USMember

    I see the same bug using the latest stable Xamarin.Forms 2.0.0.6490 with the same configuration as above (AbsoluteLayout as root). The issue shows up on Android but not on iOS, just like with the original poster.

    This is a really unfortunate bug.

  • AndrewVoganAndrewVogan USMember

    Entered it in Bugzilla, and crossing my fingers.

    https://bugzilla.xamarin.com/show_bug.cgi?id=36574

  • AndrewVoganAndrewVogan USMember

    Partial progress on this. I can get the keyboard to force scrolling if I set the activity's window's soft input mode as follows:

    Java:
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    C#:
    this.Window.SetSoftInputMode(SoftInput.AdjustPan);

    ... however, when the keyboard is displayed I can't scroll by touch, so it's like it doesn't recognize that the keyboard shrinks the available/usable size.

  • alexeyNalexeyN UAMember ✭✭

    I had the same issue.

    craigsprogramming.com/2013/03/here-is-helpful-utility-class-for.html

    That blog helped me to resolve it. Thank the guy who wrote it.

    I created a renderer for an entry and added a custom focus method.

    private void AndroidFocusSimulate(object sender, EventArgs e) { var downTime = SystemClock.UptimeMillis(); var eventTime = SystemClock.UptimeMillis(); var rect = new Rect(); Control.GetDrawingRect(rect); var x = rect.CenterX(); var y = rect.CenterY(); Control.DispatchTouchEvent(MotionEvent.Obtain(downTime, eventTime, MotionEventActions.Down, x, y, 0)); Control.DispatchTouchEvent(MotionEvent.Obtain(downTime, eventTime, MotionEventActions.Up, x, y, 0)); Control.DispatchKeyEvent(new KeyEvent(downTime,eventTime,KeyEventActions.Multiple, Keycode.MoveEnd, 1)); RendererHelper.ShowSoftKeyboard(this.Context as Activity, Control); }

    ShowSoftKeyboard method is from the blog.

    public static void ShowSoftKeyboard(Activity activity, View view = null, int delay = 200) { new Handler().PostDelayed(delegate { view = view ?? activity.CurrentFocus; if (view != null) { if (view.HasFocus) view.ClearFocus(); view.RequestFocus(); InputMethodManager manager = (InputMethodManager)activity.GetSystemService(Context.InputMethodService); manager.ShowSoftInput(view, 0); } }, delay); }

    I hope it helps

Sign In or Register to comment.