如何解决搜索栏拇指居中问题
我已经设置了搜索栏的拇指图像,但我的拇指看起来略低于搜索栏。如何将拇指设置在搜索栏的正确位置。看看附加的图片
<SeekBar android:id="@+id/PP_Player_SeekBar"
android:thumb="@drawable/music_player_playerhead"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:progressDrawable="@drawable/seekbar_drawable_xml_background"
android:layout_width="236dip"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="47dip"></SeekBar>
谢谢 苏尼尔·库马尔·萨乌
I have set thumb image of a seek bar but my thumb looks little below of seek bar. How to set thumb at proper position of a seekbar. Have a look on the attached image
<SeekBar android:id="@+id/PP_Player_SeekBar"
android:thumb="@drawable/music_player_playerhead"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:progressDrawable="@drawable/seekbar_drawable_xml_background"
android:layout_width="236dip"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="47dip"></SeekBar>
Thanks
Sunil Kumar Saoo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
设置minHeight和maxHeight与seekbar的高度相同。例如
参见以下网址
http://qtcstation.com/ 2011/05/android-如何修复-seekbar-bar-thumb-centering-issues/
Set minHeight and maxHeight same as the height of seekbar. eg
See the following url
http://qtcstation.com/2011/05/android-how-to-fix-seekbar-bar-thumb-centering-issues/
事实上,将
maxHeight
定义为像 1000dp 这样的大数字就足够了。这也有使用
height=wrap_content
和height=match_parent
的好处。In fact, it is enough to define
maxHeight
to a big number like 1000dp.This also has the benefit of working with
height=wrap_content
andheight=match_parent
.对我来说,这个问题更与背景的垂直居中有关(可绘制轨道)。这是我最初使用的有缺陷的可绘制代码(产生了问题),正如 Android 开发人员和其他 StackOverflow 条目所建议的那样:
这里的问题是第一项,它与SeekBar的背景有关。许多条目会告诉您将layout_minHeight功能设置为某个较大的值,以避免拇指与其轨道之间的垂直空间脱节。这对我来说不是解决方案 - 当在平板电脑上查看时,背景仍然绘制到较小的基于手机的尺寸 - 因此轨道始终位于 SeekBar 轨道中心上方。解决方案是在 SeekBar 可绘制对象中删除此条目,因此它现在看起来像这样:
然后,在 SeekBar 的样式定义中,将layout_background 设置为轨道可绘制对象。我的看起来像这样:(
以前,这里的背景设置只是一种颜色[白色]。)。
这是我的布局中的条目,它同时使用样式和可绘制对象:
因此,总而言之,不要在自定义 SeekBar 可绘制对象中设置背景(轨道)功能,而是在自定义 SeekBar 样式的layout_background 功能中设置它。这可确保轨道始终在水平 SeekBar 中垂直居中。
For me, the issue is more related to the vertical centering of the background (track drawable). This is the flawed drawable code I used originally (which generated the problem), as suggested by Android developer and other StackOverflow entries:
The problem here is the first item, which relates to the background of the SeekBar. Many entries will tell you to set the layout_minHeight feature to some large value to avoid a vertical spatial disconnect between the thumb and its track. This was not the solution for me - when viewed on a tablet, the background was still drawing to its smaller phone-based size - so the track was consistently positioned well above the center of the SeekBar track. The solution is to remove this entry in the SeekBar drawable, so it now looks like this:
Then, in the style definition of the SeekBar, set the layout_background to the the track drawable. Mine looks like this:
(Previously, the background setting here was just a color [white].).
This is the entry in my layout, which uses both the style and the drawables:
So, to summarize, do not set the background (track) feature in your custom SeekBar drawable, set it in the layout_background feature of your custom SeekBar style. This ensures the track is always vertically centered in a horizontal SeekBar.
我只是通过将搜索栏的
layout_height
设置为wrap_content
而不是match_parent
解决了未对齐的水平搜索栏拇指问题I simply resolved the misaligned horizontal seekbar thumb by setting
layout_height
of the seekbar towrap_content
instead ofmatch_parent