为什么我的搜索栏左右两侧有空格?

Why are there spaces on the left and right hand side of my seekbar?

我正在处理 Seekbar,我发现了一个问题。默认值 space 出现在左侧和右侧。我需要搜索栏是全宽的。我做了 match_parentfill_parent,但没有用。

<?xml version="1.0" encoding="utf-8"?>

 <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <SeekBar
      android:id="@+id/seek_bar_controller"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="0dp" />
 </RelativeLayout>

您可以按照此快照进行参考,左右手边都有space。

请仔细阅读我的 post 并提出一些解决方案。

要删除它,您需要使用 android:thumbOffset="20dp"

试试下面的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SeekBar
        android:id="@+id/seek_bar_controller"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:thumbOffset="20dp" />
</RelativeLayout>

试试下面的 XML,它对我有用:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

     <SeekBar
          android:id="@+id/seek_bar_controller"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:thumbOffset="10dp"
          android:paddingLeft="5dp"
         android:paddingRight="5dp"/>

 </RelativeLayout>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SeekBar
android:id="@+id/seek_bar_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
/* In your activity */
SeekBar seekBar=(SeekBar)findViewById(R.id.seek_bar_controller);
seekBar.setPadding(0, 0, 0, 0);