简体   繁体   中英

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

I am working on Seekbar and i have found one issue. A default space is present on the left and right hand side. I need the seekbar to be full width. I did match_parent and fill_parent but that didn't work.

在此处输入图片说明

<?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>

You can follow this snapshot for the reference, on both left and right hand sides space is present.

Please kindly go through my post and suggest some solution.

<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);

To remove that you need to use android:thumbOffset="20dp" ,

try below code :

<?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>

Try the XML below, it worked for me:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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