以编程方式添加时,单选按钮不会出现在屏幕上

Radio Buttons don't appear on screen when added programatically

我在按钮点击处理程序中有以下代码:

LinearLayout linearLayoutParent = FindViewById<LinearLayout>(Resource.Id.linearLayoutParent);
LinearLayout linearLayoutFileTransferVia = new LinearLayout(this);
TextView labelFileTransferViaInfo = new TextView(this);
labelFileTransferViaInfo.LayoutParameters = lp;
labelFileTransferViaInfo.Text = "Choose file transfer via to FTP Server";
labelFileTransferViaInfo.SetTextAppearance(Android.Resource.Style.TextAppearanceLarge);
RadioButton rbWiFi = new RadioButton(this);
RadioButton rb3G = new RadioButton(this);
RadioGroup radioGroupFileTransferType = new RadioGroup(this);
radioGroupFileTransferType.Orientation = Orientation.Horizontal;
rbWiFi.Text = "Wi-Fi";
rb3G.Text = "3G";
radioGroupFileTransferType.AddView(rbWiFi);
radioGroupFileTransferType.AddView(rb3G);
linearLayoutFileTransferVia.AddView(labelFileTransferViaInfo);
linearLayoutFileTransferVia.AddView(radioGroupFileTransferType);
linearLayoutParent.AddView(linearLayoutFileTransferVia);

当我单击按钮时,labelFileTransferViaInfo 会出现在屏幕上,但 radioGroupFileTransferType 不会。您认为发生这种情况的问题是什么?

我认为你需要像那样添加 LayoutParams

            LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.MATCH_PARENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);

radioGroupFileTransferType.AddView(rbWiFi, layoutParams);
radioGroupFileTransferType.AddView(rb3G, layoutParams);