我将动态数据添加到LinearLayout。默认我在xml中声明为垂直方向。但是我需要通过编程方式加载水平数据,这里设置Orientation不起作用。
LinearLayout llQuestionLayout = (LinearLayout) findViewById(R.id.ll_question_layout);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llQuestionLayout.setLayoutParams(layoutParams);
llQuestionLayout.setOrientation(LinearLayout.HORIZONTAL);
private void populateLikert() {
if(llQuestionLayout.getChildCount() > 0) {
llQuestionLayout.removeAllViews();
}
RadioGroup radioGroup = new RadioGroup(this);
for(int i =0; i < 5; i++) {
RadioButton radioButton = (RadioButton) LayoutInflater.from(this).inflate(R.layout.likert_radio_button, null, false);
radioButton.setText("" + (i + 1));
radioGroup.addView(radioButton);
}
llQuestionLayout.addView(radioGroup);
}
<LinearLayout
android:id="@+id/ll_question_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:orientation="vertical"/>
请建议正确答案。