Android 程序生成的布局

Android 程序生成的布局,android,android-layout,Android,Android Layout,我从一个API获取了一些数据,并生成了一个Android布局,但我无法实现一个漂亮的布局,正如你在下面看到的那样 对于我收到的每一个新数据,我都希望在TextView下显示TextView->RadioGroup。这总是一个问题和一个广播小组 这是我的密码: @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceSta

我从一个API获取了一些数据,并生成了一个Android布局,但我无法实现一个漂亮的布局,正如你在下面看到的那样

对于我收到的每一个新数据,我都希望在TextView下显示TextView->RadioGroup。这总是一个问题和一个广播小组

这是我的密码:

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_checklist);

        Intent intent = getIntent();
        int size = intent.getIntExtra("size", 0);
        Log.d(TAG, "onCreate - Qtd Questões: " + size);

        ScrollView scrollView= new ScrollView(this);
        RelativeLayout layout = new RelativeLayout(this);

        for (int i=0; i<size;i++) {

            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(layoutParams);

RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

            TextView tv1 = new TextView(this);
            tv1.setId(i+1);
            tv1.setText(intent.getStringExtra("q"+i));
            params1.addRule(RelativeLayout.BELOW, tv1.getId());

            // Initialize a new RadioGroup
            RadioGroup rg = new RadioGroup(getApplicationContext());
            rg.setOrientation(RadioGroup.HORIZONTAL);
            params2.addRule(RelativeLayout.BELOW, tv1.getId());
            rg.setId(i+1);

            // Create a Radio Button for RadioGroup
            RadioButton rb_sim = new RadioButton(getApplicationContext());
            rb_sim.setText("Sim");
            rb_sim.setId(i+i);
            rg.addView(rb_sim);

            RadioButton rb_nao = new RadioButton(getApplicationContext());
            rb_nao.setText("Não");
            rb_nao.setId(i+i);
            rg.addView(rb_nao);

            RadioButton rb_na = new RadioButton(getApplicationContext());
            rb_na.setText("Não se Aplica");
            rb_na.setId(i+i);
            rg.addView(rb_na);

            if (i > 0) {
                params1.addRule(RelativeLayout.BELOW, rg.getId());
                layout.addView(tv1,params1);
            } else {
                layout.addView(tv1);
            }
            layout.addView(rg, params2);
        }

        scrollView.addView(layout);
        setContentView(scrollView);
    }

可能我离它很近,但我看不出有什么问题。

尝试更改相对于线性的布局,然后检查输出

RelativeLayout layout = new RelativeLayout(this);


希望这显示您的视图正常,而不是与文本视图重叠。

收音机在tv1中使用得更多。由于您有一些列表要呈现,我认为最好使用带有ArrayAdapter的ListView。最好使用RecyclerView,不是吗?
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);