【问题标题】:Radio Buttons don't appear on screen when added programatically以编程方式添加时,单选按钮不会出现在屏幕上
【发布时间】:2017-11-16 08:19:37
【问题描述】:

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

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 没有。您认为发生这种情况的问题是什么?

【问题讨论】:

  • 尝试为您的线性布局设置方向。
  • 我已经完成了我只是没有在这里粘贴代码所以它不会那么长。

标签: android radio-button appearance


【解决方案1】:

我认为您需要像这样添加 LayoutParams

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 2018-05-21
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多