如何对齐 Android 中的单选按钮文本?
How to align Radio Button text in Android?
android.I 的新手正在使用我的 android 应用程序中的单选按钮
questionbtnD = (RadioButton)findViewById(R.id.optionD);
questionbtnD.setText(Html.fromHtml(dq.get(id).getOptions().get(3).toString().trim()));
并且即将到来的文本类似于
<![CDATA[ <p> Won't compile because of line (1) – constructor can't be private </p> ]]>
但是它没有正确对齐 任何人都可以帮助我如何对齐它。
这应该会让您了解如何使用 LayoutParams
RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 32, 0, 0);
RadioButton rButton = new RadioButton(getActivity());
rButton.setText("stuff");
rButton.setLayoutParams(layoutParams);
rButton.setPadding(140, 0, 40, 0);
radioGroupPair.addView(rButton);
这是xml
<RadioGroup
android:id="@+id/radioGroupPair"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RadioGroup>
最后,我在 HTML 中发现了问题,我使用的是
,它提供了额外的一行,因此我得到了额外的 lank 行,现在我删除了 标签
<![CDATA[ Won't compile because of line (1) – constructor can't be private ]]>
所以它现在对我来说工作正常
android.I 的新手正在使用我的 android 应用程序中的单选按钮
questionbtnD = (RadioButton)findViewById(R.id.optionD);
questionbtnD.setText(Html.fromHtml(dq.get(id).getOptions().get(3).toString().trim()));
并且即将到来的文本类似于
<![CDATA[ <p> Won't compile because of line (1) – constructor can't be private </p> ]]>
但是它没有正确对齐 任何人都可以帮助我如何对齐它。
这应该会让您了解如何使用 LayoutParams
RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 32, 0, 0);
RadioButton rButton = new RadioButton(getActivity());
rButton.setText("stuff");
rButton.setLayoutParams(layoutParams);
rButton.setPadding(140, 0, 40, 0);
radioGroupPair.addView(rButton);
这是xml
<RadioGroup
android:id="@+id/radioGroupPair"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RadioGroup>
最后,我在 HTML 中发现了问题,我使用的是
,它提供了额外的一行,因此我得到了额外的 lank 行,现在我删除了标签
<![CDATA[ Won't compile because of line (1) – constructor can't be private ]]>
所以它现在对我来说工作正常