在ScrollView中调整Android RadioGroup的大小

时间:2017-08-20 20:52:58

标签: java android radio-button scrollview

我在ScrollView中的RadioGroup中有很多RadioButtons(通过Java动态添加)。问题是我不知道如何调整大小以使其适合屏幕。我的代码:

    ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.layout);
    RadioGroup radioGroup = new RadioGroup(this);
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT
    );
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
    {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            btnEditFolder.setEnabled(true);
            btnViewFolder.setEnabled(true);
        }
    });
    for(int i =0; i<foldersArray.length;i++)
    {
        RadioButton radioButtonView = new RadioButton(this);
        radioButtonView.setText(foldersArray[i]);
        radioGroup.addView(radioButtonView, p);
    }
    ScrollView svFolders = new ScrollView(getApplicationContext());
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    radioGroup.setLayoutParams(params);
    radioGroup.getLayoutParams().height = screenHeight - 300;
    svFolders.setX(50);
    svFolders.setY(100 + btnEditFolder.getMeasuredHeight());
    svFolders.addView(radioGroup);
    layout.addView(svFolders, p);

ScrollView位于y轴的下方,我认为它仍然与屏幕相同的高度使其离开屏幕。

Here's a screenshot

0 个答案:

没有答案