user interface - How to position a view right above the keyboard? -
i'm writing forms app. how position view right @ bottom of screen , when entry focused , keyboard visible, view right above keyboard? on android, possible set window.setsoftinputmode(softinput.adjustresize)
, make content
resize every time keyboard appearing/disappearing. however, need status bar transparent , softinput.adjustresize
doesn't work windowmanagerflags.translucentstatus
. question is, how position view right above keyboard without setting softinput.adjustresize
?
take example:
public page1() { initializecomponent(); var al = new stacklayout { horizontaloptions = layoutoptions.fillandexpand, verticaloptions = layoutoptions.fillandexpand }; var button = new boxview {color = color.red, verticaloptions = layoutoptions.endandexpand}; var entry = new entry {horizontaloptions = layoutoptions.fill}; al.children.add(entry); al.children.add(button); content = al; content.sizechanged += (sender, args) => { button.layout(new rectangle(0, content.height - 120, app.dimensions.width, 120)); }; }
if run code, when you'll press input, nothing change, "button" remain on bottom of screen not visible because of overlaying keyboard.
if add window.setsoftinputmode(softinput.adjustresize)
in mainactivity's oncreate works fine, box moved above keyboard on entry's focus.
also, if change content = al;
content = new scrollview {content = al};
, works fine.
however, if add window.addflags(windowmanagerflags.translucentstatus);
in mainactivity's oncreate, none of methods work anymore.
thanks in advance.
i'm writing forms app. how position view right @ bottom of screen , when entry focused , keyboard visible, view right above keyboard?
if using xamarin forms, wrapping ui elements in scrollview should trick. if using xaml:
<scrollview> <scrollview.content> // original xaml content here </scrollview.content> <scrollview
edit:
looking @ example added, think know happening. so, scrollview trick works elements require keyboard input. i.e if instead had entry element @ bottom of screen, , wrapped in scrollview suggested, keyboard should push entry element you. in case have boxview @ bottom of screen, keyboard runs over.
what have content.sizedchanged idea, don't think size of view changes when keyboard pops (at least, content.sizechanged isn't called when keyboard pops up), part of code called on loading of page mcve provided.
however, able move 'button' when keyboard appears doing this:
replace
content.sizechanged += (sender, args) => { button.layout(new rectangle(0, content.height - 120, app.dimensions.width, 120)); };
with
entry.focused += (sender, e) => { button.translationy -= 120; };
you may have heck of time getting magic translation number different devices , orientations though. when tested on iphone 6 simulator had push way above 120 before see above keyboard.
hope helps!
Comments
Post a Comment