这是我用来生成视图对象的代码:
// creates the seekBar
sBGauge = new SeekBar(this);
sBGauge.setMax(depthL - 1);
sBGauge.setMinimumWidth(150);
sBGauge.setId(2000 + i);
sBGauge.setOnSeekBarChangeListener(this);
不管我设置sBGauge.setMinimumWidth();它似乎总是只有20左右。
任何想法? 感谢
编辑:提供更多信息我在一个tablerow中的两个textView之间使用此搜索栏。
凸块
答案 0 :(得分:1)
试试这个
LayoutParams lp = new LayoutParams(150, 150);
sBGauge.setLayoutParams(lp);
您可以根据需要更改值150和150.
答案 1 :(得分:1)
解决此问题我必须做的是从TableLayout中动态创建的TableRow更改为LinearLayout。然后,我能够获得我的屏幕宽度并减去我的文本视图,然后使用结果数字设置搜索栏的宽度。
// gets the width of the screen to set the seekbar width
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
width = width - 170;
LinearLayout lL = new LinearLayout(this);
// creates the seekBar
sBGauge = new SeekBar(this);
sBGauge.setMax(depthL - 1);
sBGauge.setId(2000 + i);
sBGauge.setLayoutParams(new LinearLayout.LayoutParams(width, 50, 1f));
sBGauge.setOnSeekBarChangeListener(this);