0

我在对话框中呈现 TextView 和 Seekbar 时遇到了一个问题。

我正在从android 网站练习本教程

问题出在 for 循环中,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();
    }

}
4

2 回答 2

1

您的LinearLayout默认值为orientation="horizontal". 将其方向更改为垂直,您将看到您想要的。

LL.setOrientation(LinearLayout.VERTICAL);
于 2012-05-25T21:03:43.527 回答
0

您的 LinearLayout 方向是否正确?

LL.setOrientation(LinearLayout.VERTICAL);
于 2012-05-25T21:03:38.113 回答