【问题标题】:Why are there spaces on the left and right hand side of my seekbar?为什么我的搜索栏左右两边都有空格?
【发布时间】:2016-03-17 10:27:12
【问题描述】:

我正在处理Seekbar,我发现了一个问题。默认空间位于左侧和右侧。我需要搜索栏是全宽的。我做了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>

您可以按照此快照作为参考,左右两侧都有空间。

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

【问题讨论】:

  • 内边距也可以来自父元素。
  • 我认为这是SeekBar 的默认属性,因为拇指使用了额外的填充。我认为你应该从双手给SeekBar 减去边距。退房
  • 分享你的父 xml

标签: android xml android-layout android-studio seekbar


【解决方案1】:
<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);

【讨论】:

  • 即使接受的答案也对我不起作用。这有作品。谢谢。
【解决方案2】:

要删除你需要使用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>

【讨论】:

    【解决方案3】:

    试试下面的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 2018-11-30
      • 2018-12-27
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多