无法设置动态创建的搜索栏的最小宽度

时间:2012-10-17 06:23:54

标签: android width seekbar css

这是我用来生成视图对象的代码:

        // 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之间使用此搜索栏。

凸块

2 个答案:

答案 0 :(得分:1)

试试这个

    LayoutParams lp = new LayoutParams(150, 150);
    sBGauge.setLayoutParams(lp);

您可以根据需要更改值150和150.

答案 1 :(得分:1)

@Amit Hooda你的解决方案并没有解决我的问题,但确实让我走上了寻找解决方案的正确道路。

解决此问题我必须做的是从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);