how to move layout up when softkeyboard shown?

Biyyapu_SuneelkumarBiyyapu_Suneelkumar USMember ✭✭
edited August 2015 in Xamarin.Forms

Hi All,
I am working on one project, where I had an issue. The issue is when I tap on entry control the softkeyboard hides the bottom content, I need it in the way when I focus 2nd entry from bottom, then I need to show that and after that control.

How can I achieve it.
any help would be greatly appreciated.

Thanks,
Suneel.

Tagged:

Answers

  • PaulDistonPaulDiston USUniversity ✭✭✭✭

    Hi,

    You could set the WindowSoftInputMode against your MainActivity for Android, as detailed in the following thread :-

    https://forums.xamarin.com/discussion/46635/detect-keyboard-open

    Hope this helps.

    Paul Diston

  • Hi Paul,
    first of all thanks for your help and whatever you said is okay,
    but I need it in Iphone and Windows Phone platforms also.

    Thanks,
    Suneel.

  • TorbenKruseTorbenKruse DEMember ✭✭✭

    @sunee Wrapping your control which displays the keyboard inside a ScrollView should do it.

  • Biyyapu_SuneelkumarBiyyapu_Suneelkumar USMember ✭✭
    edited August 2015

    Hi All,
    I have resolved the issue using the following snippet.

    public class EntryKeyboards : ContentPage
    {
    ScrollView scrollMain = null;
    StackLayout stackMain = null;
    public EntryKeyboards()
    {
    //FirstName
    var lblFName = new Label
    {
    Text = "First Name",
    };
    var txtFName = new Entry
    {
    HorizontalOptions = LayoutOptions.FillAndExpand,
    };
    var stackFName = new StackLayout
    {
    Orientation = StackOrientation.Vertical,
    Children = { lblFName, txtFName },
    };

            //Last Name
            var lblLName = new Label
            {
                Text = "Last Name:",
            };
            var txtLName = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackLName = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblLName, txtLName }
            };
    
            //Age
            var lblAge = new Label
            {
                Text = "Age:",
            };
            var txtAge = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackAge = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblAge, txtAge }
            };
    
            //Dob
            var lblDob = new Label
            {
                Text = "DateOfBirth:",
            };
            var txtDob = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackDob = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblDob, txtDob }
            };
    
    
            //Address
            var lblAdrs = new Label
            {
                Text = "Address:",
            };
            var txtAdrs = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackAdrs = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblAdrs, txtAdrs }
            };
    
    
            //Mobile
            var lblMobile = new Label
            {
                Text = "Mobile:",
            };
            var txtMobile = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackMobile = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblMobile, txtMobile }
            };
    
    
            //Father Name
            var lblFather = new Label
            {
                Text = "Father Name:",
            };
            var txtFather = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackFather = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblFather, txtFather }
            };
    
    
            //Mother Name
            var lblMother = new Label
            {
                Text = "Mother Name:",
            };
            var txtMother = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackMother = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblMother, txtMother }
            };
    
    
            //Class
            var lblClass = new Label
            {
                Text = "Class:",
            };
            var txtClass = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackClass = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblClass, txtClass }
            };
    
    
            //RollNumber 
            var lblRno = new Label
            {
                Text = "Roll No:",
            };
            var txtRno = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var stackRno = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Children = { lblRno, txtRno }
            };
    
    
            stackMain = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Spacing = 6,
                Children = { 
                             stackFName,
                             stackLName,
                             stackFather,
                             stackMother,
                             stackRno,
                             stackClass,
                             stackAge,
                             stackAdrs,
                             stackDob,
                             stackMobile,
                             new StackLayout{ Children={ new Button{Text="Submit"}}}
                           }
    
            };
            scrollMain = new ScrollView
            {
                Content = stackMain,
                Orientation = ScrollOrientation.Vertical,
            };
            //(scrollMain.Height / stackMain.Children.Count)
            //1
            //txtFName.Focused += async (s, e) =>
            //    {
            //        await scrollMain.ScrollToAsync(0, 40 , true);
            //    };
    
            //2
            txtLName.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  + (40)*2 , true);
            };
            //3
            txtFather.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 3 , true);
            };
            //4
            txtMother.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 4 , true);
            };
            //5
            txtRno.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 5 , true);
            };
            //6
            txtClass.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 6 , true);
            };
            //7
            txtAge.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 7 , true);
            };
            //8
            txtAdrs.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 8 , true);
            };
            //9
            txtDob.Focused += async (s, e) =>
            {
                await scrollMain.ScrollToAsync(0,  (40) * 9 , true);
            };
            //10
            txtMobile.Focused += async (s, e) =>
                {
                    await scrollMain.ScrollToAsync(0,  (40) * 10 , true);
                };
            Content = scrollMain;
        }
    
    }
    
Sign In or Register to comment.