Cannot set minimum width for dynamically created search button

here is the code i use to create my view object:

// creates the seekBar sBGauge = new SeekBar(this); sBGauge.setMax(depthL - 1); sBGauge.setMinimumWidth(150); sBGauge.setId(2000 + i); sBGauge.setOnSeekBarChangeListener(this); 

no matter what i set sBGauge.setMinimumWidth (); he will always be only about 20.

any thoughts? thanks

Edit: to get more information, I use this search bar between two text elements in the scoreboard.

cone

+4
source share
2 answers

@ Please, Hooda your solution did not solve my problem, but it really led me to the right way to find a solution.

What I had to do to fix this problem was to switch from a dynamically created TableRow to LinearLayout in my TableLayout. Then I was able to get the width of the screen and subtract my text images, and then set the width of the search string with the resulting number.

 // 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); 
+1
source

try it

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

You can change the value of 150 and 150 according to your needs.

+1
source

Source: https://habr.com/ru/post/1440214/


All Articles