如何解决搜索栏拇指居中问题

发布于 2024-12-04 12:01:44 字数 639 浏览 4 评论 0原文

我已经设置了搜索栏的拇指图像,但我的拇指看起来略低于搜索栏。如何将拇指设置在搜索栏的正确位置。看看附加的图片在此处输入图片描述

<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 imageenter image description here

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花之痕靓丽 2024-12-11 12:01:44

设置minHeight和maxHeight与seekbar的高度相同。例如

<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"
    android:minHeight="11dip"
    android:maxHeight="11dip" />

参见以下网址
http://qtcstation.com/ 2011/05/android-如何修复-seekbar-bar-thumb-centering-issues/

Set minHeight and maxHeight same as the height of seekbar. eg

<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"
    android:minHeight="11dip"
    android:maxHeight="11dip" />

See the following url
http://qtcstation.com/2011/05/android-how-to-fix-seekbar-bar-thumb-centering-issues/

伤痕我心 2024-12-11 12:01:44

事实上,将 maxHeight 定义为像 1000dp 这样的大数字就足够了。

这也有使用 height=wrap_contentheight=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 and height=match_parent.

み格子的夏天 2024-12-11 12:01:44

对我来说,这个问题更与背景的垂直居中有关(可绘制轨道)。这是我最初使用的有缺陷的可绘制代码(产生了问题),正如 Android 开发人员和其他 StackOverflow 条目所建议的那样:

<item
    android:id="@android:id/background"
    android:drawable="@drawable/seekbar_track"/>
<item android:id="@android:id/secondaryProgress">
    <scale
        android:drawable="@drawable/seekbar_progress2"
        android:scaleWidth="100%" />
</item>
<item android:id="@android:id/progress">
    <scale
        android:drawable="@drawable/seekbar_progress"
        android:scaleWidth="100%" />
</item>

这里的问题是第一项,它与SeekBar的背景有关。许多条目会告诉您将layout_minHeight功能设置为某个较大的值,以避免拇指与其轨道之间的垂直空间脱节。这对我来说不是解决方案 - 当在平板电脑上查看时,背景仍然绘制到较小的基于手机的尺寸 - 因此轨道始终位于 SeekBar 轨道中心上方。解决方案是在 SeekBar 可绘制对象中删除此条目,因此它现在看起来像这样:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/secondaryProgress">
        <scale
            android:drawable="@drawable/seekbar_progress2"
            android:scaleWidth="100%" />
    </item>
    <item android:id="@android:id/progress">
        <scale
            android:drawable="@drawable/seekbar_progress"
            android:scaleWidth="100%" />
    </item>

</layer-list>

然后,在 SeekBar 的样式定义中,将layout_background 设置为轨道可绘制对象。我的看起来像这样:(

<style name="styleSeekBar" parent="@android:style/Widget.SeekBar">
    <item name="android:padding">@dimen/base_0dp</item>
    <item name="android:background">@drawable/seekbar_track</item>
    <item name="android:progressDrawable">@drawable/abratingbar</item>
    <item name="android:minHeight">@dimen/base_29dp</item>
    <item name="android:maxHeight">@dimen/base_29dp</item>
    <item name="android:layout_marginLeft">@dimen/base_10dp</item>
    <item name="android:layout_marginRight">@dimen/base_10dp</item>
    <item name="android:layout_marginTop">@dimen/base_10dp</item>
    <item name="android:layout_marginBottom">@dimen/base_10dp</item>
    <item name="android:scaleType">fitXY</item>
</style>

以前,这里的背景设置只是一种颜色[白色]。)。

这是我的布局中的条目,它同时使用样式和可绘制对象:

<SeekBar
    android:id="@+id/seekbar_page_number"
    style="@style/styleSeekBar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/base_29dp"
    android:minHeight="@dimen/base_29dp"
    android:maxHeight="@dimen/base_29dp"
    android:layout_marginLeft="@dimen/base_230dp"
    android:layout_gravity="bottom|right"
    android:progress="1"
    android:max="20"
    android:progressDrawable="@drawable/abseekbar"
    android:thumb="@drawable/abseekbar_thumb"/>

因此,总而言之,不要在自定义 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:

<item
    android:id="@android:id/background"
    android:drawable="@drawable/seekbar_track"/>
<item android:id="@android:id/secondaryProgress">
    <scale
        android:drawable="@drawable/seekbar_progress2"
        android:scaleWidth="100%" />
</item>
<item android:id="@android:id/progress">
    <scale
        android:drawable="@drawable/seekbar_progress"
        android:scaleWidth="100%" />
</item>

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:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/secondaryProgress">
        <scale
            android:drawable="@drawable/seekbar_progress2"
            android:scaleWidth="100%" />
    </item>
    <item android:id="@android:id/progress">
        <scale
            android:drawable="@drawable/seekbar_progress"
            android:scaleWidth="100%" />
    </item>

</layer-list>

Then, in the style definition of the SeekBar, set the layout_background to the the track drawable. Mine looks like this:

<style name="styleSeekBar" parent="@android:style/Widget.SeekBar">
    <item name="android:padding">@dimen/base_0dp</item>
    <item name="android:background">@drawable/seekbar_track</item>
    <item name="android:progressDrawable">@drawable/abratingbar</item>
    <item name="android:minHeight">@dimen/base_29dp</item>
    <item name="android:maxHeight">@dimen/base_29dp</item>
    <item name="android:layout_marginLeft">@dimen/base_10dp</item>
    <item name="android:layout_marginRight">@dimen/base_10dp</item>
    <item name="android:layout_marginTop">@dimen/base_10dp</item>
    <item name="android:layout_marginBottom">@dimen/base_10dp</item>
    <item name="android:scaleType">fitXY</item>
</style>

(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:

<SeekBar
    android:id="@+id/seekbar_page_number"
    style="@style/styleSeekBar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/base_29dp"
    android:minHeight="@dimen/base_29dp"
    android:maxHeight="@dimen/base_29dp"
    android:layout_marginLeft="@dimen/base_230dp"
    android:layout_gravity="bottom|right"
    android:progress="1"
    android:max="20"
    android:progressDrawable="@drawable/abseekbar"
    android:thumb="@drawable/abseekbar_thumb"/>

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.

书间行客 2024-12-11 12:01:44

我只是通过将搜索栏的 layout_height 设置为 wrap_content 而不是 match_parent 解决了未对齐的水平搜索栏拇指问题

I simply resolved the misaligned horizontal seekbar thumb by setting layout_height of the seekbar to wrap_content instead of match_parent

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文