2017-01-20 9 views
0

私はカスタムキーボード用にこのコードを持っています。xamarin.formsアンドロイド - 線形レイアウトが期待通りに表示されない

そのxamarin.forms for android。

キーボードをページの下部から提示し、必要に応じてエントリを上げたいとします。

結果として、キーボードはページの上に表示され、エントリが上部にある場合はそのエントリをカバーします。

public class CustomEntryRenderer : EntryRenderer 
{ 
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
    { 
     base.OnElementChanged(e); 

     if (Control == null) 
      return; 

     Android.InputMethodServices.Keyboard numericKeyboard = new Android.InputMethodServices.Keyboard(Control.Context, Resource.Xml.keyboard2); 
     CustomKeyboardView numericKeyboardView = new CustomKeyboardView(Control.Context, null); 
     numericKeyboardView.Id = Control.Id; 
     numericKeyboardView.Keyboard = numericKeyboard; 
     numericKeyboardView.Visibility = ViewStates.Gone; 
     numericKeyboardView.PreviewEnabled = false; 

     ///////////////////////////////////////////////// 
     // THIS IS THE LAYOUT CREATION 
     //////////////////////////////////////////////// 
     LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); // maybe WrapContent on all 
     lp.Gravity = GravityFlags.Bottom; 
     lp.BottomMargin = 0; 

     ///////////////////////////////////////////////// 

     Activity activity = this.Context as Activity; 

     activity.AddContentView(numericKeyboardView, lp); 

     Control.Touch += (sender, ex2) => 
     { 
      if (numericKeyboardView.Visibility == ViewStates.Gone) 
      { 
       //Xamarin.Forms.Animation animation = Android.Views.Animations.AnimationUtils.LoadAnimation(
       Android.Views.Animations.Animation animation = Android.Views.Animations.AnimationUtils.LoadAnimation(
       this.Context, 
        Resource.Animation.slide_in_bottom 
       ); 
       numericKeyboardView.ShowWithAnimation(animation); 
       numericKeyboardView.Visibility = ViewStates.Visible; 
      } 

      ex2.Handled = true; 
     };      
    } 
} 

答えて

0

私はキーボードは、ページの下部から提示されるように、必要に応じてエントリを上げたいです。

あなたはRelativeLayoutであなたのnumericKeyboardViewをラップし、AlignParentBottomのルールを設定する必要があります。

OnElementChanged

方法では、以下のコードを追加します

//Create RelativeLayout for Keyboard 
Android.Widget.RelativeLayout rl = new Android.Widget.RelativeLayout(this.Context); 
//Create the LayoutParams for Keyboard 
Android.Widget.RelativeLayout.LayoutParams rlp = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.FillParent, LayoutParams.WrapContent); 
//set the AlignParentBottom rule 
rlp.AddRule(LayoutRules.AlignParentBottom); 
//set the LayoutParams to Keyboard 
numericKeyboardView.LayoutParameters = rlp; 
//add the keyboard to RelativeLayout 
rl.AddView(numericKeyboardView); 
//get current activity 
Activity activity = this.Context as Activity; 
//Add the Layout View to activity 
activity.AddContentView(rl,rlp); 
関連する問題