How to make SeekBar take up full width of parent

混江龙づ霸主 提交于 2019-12-04 18:41:36

问题


I have a SeekBar in a RelativeLayout whose width is equal to the screen width.

I applied layout_width="match_parent" to the SeekBar but it seems to keep some empty space on both sides of the SeekBar to accommodate the thumb.

I also tried using android:thumb="@null" The thumb is gone but not the empty space on the sides.

I really need to make the SeekBar width match the parent's. Could somebody help me with this? Maybe I could create a custom SeekBar class and set the width to the parent width in onMeasure(). If this is a possible solution, I don't know how I could pass the parent width to the SeekBar class.

Any help is appreciated. Thank you.


回答1:


Try to define following with the SeekBar in xml:

android:padding="0dp"



回答2:


 android:paddingStart="0dp"
 android:paddingEnd="0dp"

Worked for me.




回答3:


Just solved this problem in my app. The thing is, even though you didn't set the seekBar padding, there may be some paddings(paddingLeft, paddingTop, paddingRight, paddingBottom, paddingStart, paddingEnd) in the theme your appTheme extends. Set these paddings to 0dp, it should work fine.




回答4:


Before you post your xml,I guess that your RelativeLayout has lines as following

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

This means your RelativeLayout do not fill up the screen,seekbar is fill up in its parent layout(RelativeLayout).So you can not get view you want.



来源:https://stackoverflow.com/questions/25617132/how-to-make-seekbar-take-up-full-width-of-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!