コード例 #1
0
ファイル: Rating_Tab.cs プロジェクト: chinochuy/Xamarin
        private void ItemCountLayout()
        {
            //ItemCount
            TextView itemLabel = new TextView(context);

            itemLabel.Text                  = "Item Count";
            itemLabel.LayoutParameters      = new FrameLayout.LayoutParams((int)(totalWidth * 0.33), ViewGroup.LayoutParams.WrapContent);
            itemLabel.Gravity               = GravityFlags.CenterVertical;
            itemLabel.TextSize              = 15;
            itemCountEntry                  = new EditText(context);
            itemCountEntry.Gravity          = GravityFlags.Left;
            itemCountEntry.Text             = itemCountPosition.ToString();
            itemCountEntry.LayoutParameters = new FrameLayout.LayoutParams((int)(totalWidth * 0.33), ViewGroup.LayoutParams.WrapContent);
            itemCountEntry.TextSize         = 16;
            itemCountEntry.InputType        = Android.Text.InputTypes.ClassPhone;
            itemCountEntry.TextChanged     += (object sender, Android.Text.TextChangedEventArgs e) => {
                if (itemCountEntry.Text.Length > 0)
                {
                    try
                    {
                        constCount = Convert.ToInt32(e.Text.ToString());
                    }
                    catch (Exception)
                    {
                        constCount = 1;
                    }
                }

                itemCountPosition = constCount;
                ApplyChanges();
            };

            TextView spaceLabel = new TextView(context);

            spaceLabel.LayoutParameters = new FrameLayout.LayoutParams((int)(totalWidth * 0.167), ViewGroup.LayoutParams.WrapContent);

            //itemCountLayout
            LinearLayout itemCountLayout = new LinearLayout(context);

            itemCountLayout.Orientation = Android.Widget.Orientation.Horizontal;
            itemCountLayout.AddView(itemLabel);
            itemCountLayout.AddView(itemCountEntry);
            proprtyOptionsLayout.AddView(itemCountLayout);

            //spaceText
            TextView spaceText4 = new TextView(context);

            spaceText4.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 60, GravityFlags.Center);
            proprtyOptionsLayout.AddView(spaceText4);

            //layout1
            LinearLayout layout1 = new LinearLayout(context);

            layout1.Orientation = Android.Widget.Orientation.Horizontal;
            layout1.AddView(spaceLabel);
            layout1.AddView(proprtyOptionsLayout);

            //propertylayout
            propertylayout.AddView(topProperty);
            propertylayout.AddView(layout1);
            propertylayout.FocusableInTouchMode = true;
            propertylayout.Touch += (object sender, View.TouchEventArgs e) =>
            {
                Rect outRect = new Rect();
                itemCountEntry.GetGlobalVisibleRect(outRect);

                if (!outRect.Contains((int)e.Event.RawX, (int)e.Event.RawY))
                {
                    itemCountEntry.ClearFocus();
                }
                hideSoftKeyboard((Activity)context);
            };
        }