如何在Android中对齐单选按钮文本?

时间:2016-06-09 14:23:12

标签: java android android-layout android-radiobutton

Android新手。我在我的Android应用程序中使用单选按钮

questionbtnD = (RadioButton)findViewById(R.id.optionD);
questionbtnD.setText(Html.fromHtml(dq.get(id).getOptions().get(3).toString().trim()));

和来的文字就像enter image description here

<![CDATA[ <p> Won't compile because of line (1) – constructor can't be private </p> ]]>

但它没有正确对齐任何身体可以帮助我如何对齐它。

2 个答案:

答案 0 :(得分:0)

这可以让您了解如何使用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>

答案 1 :(得分:0)

最后,我发现HTML中的问题我正在使用

这给了一个额外的行,因为我得到了额外的一个lank现在我删除了

标签

<![CDATA[     Won't compile because of line (1) – constructor can't be private  ]]>

所以它现在对我来说很好

相关问题