对我有用的解决方案:
foreach (var option in options)
{
RadioButton rb = new RadioButton(Context);
rb.SetButtonDrawable(null);
rb.SetCompoundDrawablesWithIntrinsicBounds(null,null,null,ContextCompat.GetDrawable(Context, Android.Resource.Drawable.ButtonRadio));
rb.Text = option.Text;
rb.Gravity = GravityFlags.Center;
radioGroup.AddView(rb);
}
// Weight für die RBs setzen
for (int i = 0; i < radioGroup.ChildCount; i++)
{
var currentRb = radioGroup.GetChildAt(i);
LinearLayout.LayoutParams rbParams = new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WrapContent) {Weight = 1};
currentRb.LayoutParameters = rbParams;
}
.axml 中的简化 RadioGroup:
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:layout_width="match_parent"
android:id="@+id/formItemScaleLayout"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/formItemScaleStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"/>
<RadioGroup
android:layout_weight="1"
android:id="@+id/formItemScaleRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</RadioGroup>
<TextView
android:id="@+id/formItemScaleEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End"/>
</LinearLayout>
梦里花落0921
相关分类