在里面ScrollView
我有一个 LinearLayout ,它又持有一个RadioButtonGroup
with RadioButtons
。我已经创建了一个带有自定义可绘制(小尺寸单选按钮)的 RadioButton,就像在第一张图片中一样,我得到滚动条。
我试图通过以下代码减小布局大小
LinearLayout.LayoutParams radio = new LinearLayout.LayoutParams( 50, 50);
但我仍然得到滚动条,如何删除滚动条。
ScrollView outerScroll = new ScrollView(this);
LinearLayout.LayoutParams outerScrollLP = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
outerScroll.setLayoutParams(outerScrollLP);
LinearLayout outerLL = new LinearLayout(this);
LinearLayout.LayoutParams outerLLLP = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
outerLL.setLayoutParams(outerLLLP);
outerLL.setOrientation(LinearLayout.VERTICAL);
//outerLL.setScrollBarStyle(LinearLayout.SCROLLBARS_OUTSIDE_OVERLAY);
outerLL.setBackgroundResource(R.drawable.bg);
//outerLL.setBackgroundColor(Color.RED);
for (QuestionModol que : queBL.getQuestion(1)) {
try {
LinearLayout quesLL = new LinearLayout(this);
LinearLayout.LayoutParams quesLP = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
quesLP.setMargins(30, 10, 30, 5);
//quesLL.setPadding(50, 30, 50, 10);
quesLL.setLayoutParams(quesLP);
quesLL.setOrientation(LinearLayout.VERTICAL);
quesLL.setBackgroundResource(R.drawable.question_wrap);
TextView queTV = new TextView(this);
LinearLayout.LayoutParams queTVLP = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
queTVLP.setMargins(10, 10, 10, 10);
queTV.setLayoutParams(queTVLP);
queTV.setPadding(10, 10, 10, 10);
queTV.setBackgroundColor(Color.BLUE);
queTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
queTV.setBackgroundResource(R.drawable.questiontext);
queTV.setText(que.getQuestion());
queTV.setTextColor(Color.WHITE);
quesLL.addView(queTV);
// Create Radio Button
RadioGroup optRadioGroup = new RadioGroup(this);
RadioGroup.LayoutParams optRadioGroupLP = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
optRadioGroupLP.setMargins(20, 0, 20, 10);
optRadioGroup.setLayoutParams(optRadioGroupLP);
optRadioGroup.setTag(que.getId());
optRadioGroup.setOrientation(RadioGroup.VERTICAL);
for(OptionsModel options : que.getOptions()) {
RadioButton rdoOptBut = new RadioButton(this);
LinearLayout.LayoutParams rdoOptButLP = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
rdoOptButLP.gravity = Gravity.CENTER;
// Hack code to remove the space b/w radio buttons
//rdoOptBut.setBackgroundColor(Color.TRANSPARENT);
rdoOptBut.setPadding(40, 0, 0, 0);
rdoOptBut.setId(options.getOptionId());
rdoOptBut.setLayoutParams(rdoOptButLP);
//rdoOptBut.setBackgroundResource(0);
rdoOptBut.setText(options.getOptionName());
rdoOptBut.setButtonDrawable(R.drawable.custom_radiobutton);
//rdoOptBut.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
optRadioGroup.addView(rdoOptBut);
}
quesLL.addView(optRadioGroup);
outerLL.addView(quesLL);
} catch (Exception e) {
// TODO: handle exception
}
}
outerScroll.addView(outerLL);