我在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轴的下方,我认为它仍然与屏幕相同的高度使其离开屏幕。