setOrientation不能以编程方式用于LinearLayout

时间:2016-11-12 09:25:03

标签: android android-linearlayout

我将动态数据添加到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"/>

请建议正确答案。

0 个答案:

没有答案