我在对话框中渲染TextView和Seekbar时面临一个问题。
练习本教程问题在于循环使用TextView& SeekBar应该被添加5次,并且应该在Dialog中显示。但只显示一个TextView。
以下是代码:
public void onCheckedChanged(RadioGroup rgroup, int rbutton) {
String eqSettingName = ((RadioButton) findViewById(rbutton)).getText()
.toString();
if (eqSettingName.equals("Custom")) {
Dialog dialog = new Dialog(this);
dialog.setTitle("Custom Equalizer");
LinearLayout LL = new LinearLayout(this);
short noOfBands = mEqualizer.getNumberOfBands();
final short minEQLevel = mEqualizer.getBandLevelRange()[0];
final short maxEQLevel = mEqualizer.getBandLevelRange()[1];
for (short i = 0; i < noOfBands; i++) {
short band = i;
TextView freqTV = new TextView(this);
freqTV.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
freqTV.setGravity(Gravity.CENTER_HORIZONTAL);
freqTV.setText((mEqualizer.getCenterFreq(band)) / 1000 + " Hz");
LL.addView(freqTV);
SeekBar bar = new SeekBar(this);
bar.setLayoutParams(layoutParams);
bar.setMax(maxEQLevel - minEQLevel);
bar.setProgress(mEqualizer.getBandLevel(band));
LL.addView(bar);
}
/*
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.customseekbar,
(ViewGroup) findViewById(R.id.rlCustomEqualizerSeekBar));
*/
dialog.addContentView(LL, layoutParams);
dialog.show();
}
}
答案 0 :(得分:1)
您的LinearLayout
默认为orientation="horizontal"
。将它的方向改为垂直方向,你会看到你想要的东西。
LL.setOrientation(LinearLayout.VERTICAL);
答案 1 :(得分:0)
您的LinearLayout是否正确定位?
LL.setOrientation(LinearLayout.VERTICAL);