简体   繁体   English

删除搜索栏中的顶部和底部填充

[英]Remove the top and bottom padding in a SeekBar

I am trying make a simple music player. 我正在尝试制作一个简单的音乐播放器。 When I try to use the android's default seek bar in my music playback controls section, there is a default padding at the top and bottom of the seekbar. 当我尝试在音乐播放控件部分使用android的默认搜索栏时,搜索栏的顶部和底部都有默认的填充。 The effect I am trying to achieve is similar to the seekbar used in shuttle music player. 我试图达到的效果类似于穿梭音乐播放器中使用的搜索栏。

在此处输入图片说明

But this the effect I'm getting. 但这就是我得到的效果。 I would be grateful if any would tell me how to achieve the desired result.I'm using linear layout as the root container. 我将不胜感激,如果有什么能告诉我如何达到理想的结果。我使用线性布局作为根容器。
在此处输入图片说明

Because the option of specifying 因为指定的选项

android:background="@color/your_colour"

will not work because you have two colors there one for the Top and one for the Bottom. 将无法使用,因为您有两种颜色,一种用于顶部,另一种用于底部。

The working solution is by using a layerlist as follows: 可行的解决方案是通过使用以下图层列表:
Go to your drawable folder create a file call it lets say back_ground_seek_bar.xml and add the following code inside it: 转到您的drawable文件夹,创建一个back_ground_seek_bar.xml的文件,并在其中添加以下代码:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
      <item android:bottom="10dp">
        <shape android:shape="rectangle" >
          <size android:height="10dp" />
          <solid android:color="@colour/your_top_color" />
        </shape>
     </item>

    <item android:top="10dp">
       <shape android:shape="rectangle" >
         <size android:height="10dp" />
         <solid android:color="@color/your_bottom_color" />
       </shape>
    </item>
  </layer-list>

Replace the colours with your own colors when you paste this. 粘贴时用自己的颜色替换颜色。 Remember we have added top and height of as 10.But because we want our SeekBar to have colour then we have to set the height of seekbar to twice the value so It should be twice and thats 20dp. 请记住,我们将top和height设置为10,但是因为我们希望SeekBar具有颜色,所以我们必须将seekbar的高度设置为该值的两倍,因此它应该为两倍,即20dp。 So we should add our new height of the seekbar to be 20dp as well set the background as the xml we have defined as follows. 因此,我们应该将搜索栏的新高度添加为20dp,并将背景设置为我们定义的xml,如下所示。 Go to your SeekBar and paste this: 转到您的SeekBar并将其粘贴:

    android:layout_height="20dp"
    android:background="@drawable/back_ground_seek_bar"

For customization you can also change the values of height and whatsoever in the drawable/back_ground_seek_bar.xml but it should always be twice. 为了进行自定义,您还可以在drawable/back_ground_seek_bar.xml更改height和其他值,但应始终为两次。 The given height set in SeekBar aim is to divide it equally. SeekBar目标中设置的给定高度是将其平均划分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM