【问题标题】:Android - Custom SeekBar - Unnecessary white space on bottom of the seekbarAndroid - 自定义 SeekBar - 搜索栏底部不必要的空白
【发布时间】:2012-05-30 11:24:35
【问题描述】:

我需要自定义搜索栏。为此,我使用了一个layer-list XML 文件,然后将其设置为 seekbar 的背景。
对于@android:id/background,我使用的是位图,对于secondaryProgressprogress,我使用的是形状。
这是 XML 背景文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/background">
        <bitmap
            android:src="@drawable/progressbar_bg"
            android:tileMode="repeat" />

    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <solid android:color="#B2B2B2" />

                <corners android:radius="5dp" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#E00072" />

                <corners android:radius="5dp" />
            </shape>
        </clip>
    </item>

</layer-list>

以下是我声明 SeekBar 的方式:

<SeekBar
                android:id="@+id/seekBar1"
                android:thumb="@drawable/progressbar_thumb"                
                android:progressDrawable="@drawable/custom_seek_bar"
                android:background="@drawable/progressbar_bg"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_toLeftOf="@id/video_total_time"
                android:layout_toRightOf="@id/video_time_played" />

问题是 SeekBar 的高度没有缩小到新的高度,我希望它与背景图像的高度相等。相反,我看到了一个充满空白的区域。

你知道空白是从哪里来的,以及如何摆脱它吗?

【问题讨论】:

  • 也对一些解决方案感兴趣 :=))))

标签: android android-layout android-intent android-emulator android-widget


【解决方案1】:

问题已通过使用 9-patch 而不是位图解决,用于 @android:id/background 项目。

 <item android:id="@android:id/background">
        <nine-patch
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:dither="true"
            android:src="@drawable/progressbar_backg" />
 </item>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多