【问题标题】:Removing rounded edges of a customized Seekbar?删除自定义 Seekbar 的圆边?
【发布时间】:2013-04-04 20:53:28
【问题描述】:

我正在尝试自定义搜索栏。我有这个主要工作,但我无法删除这个搜索栏的圆边。我知道这方面有很多问题,应用角点 0dp 会有所帮助,但我不知道在哪里实现这个形状。当我尝试显示形状时,边缘变得锐利,但我的背景没有显示,它显示为黑色矩形。我希望我的背景有锋利的边缘。

seekbarprogrss.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
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
            android:src="@drawable/cover_back" />
    </item>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/seek_progress_bg"/>

</layer-list>

seek_progress_bg.xml

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

    <item>
        <clip>
        <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@drawable/cover_front"
            android:tileMode="repeat"
            android:antialias="true"
            android:dither="false"
            android:filter="false"
            android:gravity="left"
        />
        </clip>
    </item>

</layer-list>

搜索栏实现

 <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button2"
        android:progress="0"
        android:secondaryProgress="0"
        android:padding="0dp"
        android:thumbOffset="0dp"
        android:progressDrawable="@drawable/seekbarprogrss"
        android:thumb="@drawable/cover"

【问题讨论】:

    标签: android rounded-corners seekbar


    【解决方案1】:

    SeekBar 自定义

    首先为 mSeekbar.java

    创建一个自定义类
    public class mSeekbar extends SeekBar{
        public seekBar (Context context) {
            super(context);
            Initialise();
        }
        public seekBar (Context context, AttributeSet attrs) {
            super(context, attrs);
            Initialise();
        }
        public seekBar (Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            Initialise();
        }
        private void Initialise(){
           this.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape));
           this.setProgressDrawable(getResources().getDrawable(R.drawable.seek_bar_base));
        }
    }
    

    然后,将此部分添加到您的 xml 中

    <"packageName".seekBar
            android:id="@+id/seekBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:thumb="@drawable/red_front"
            android:padding="0dp"
            android:progress="0"
            android:indeterminate="false"
            android:secondaryProgress="0"
            android:thumbOffset="0dp"/>
    

    使用这些 Drawables

    seek_bar_base.xml

    <layer-list 
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item 
            android:id="@android:id/background">
            <bitmap 
                android:src="@drawable/gray_back"
                android:tileMode="repeat">
            </bitmap>
        </item>
        <item 
            android:id="@android:id/progress">
            <layer-list 
                xmlns:android="http://schemas.android.com/apk/res/android" >
                <item>
                    <clip >
                        <bitmap 
                            xmlns:android="http://schemas.android.com/apk/res/android"
                            android:src="@drawable/gray_front"
                            android:tileMode="repeat"/>
                    </clip>
                </item>
            </layer-list>
        </item>
    </layer-list>
    

    shape.xml

     <shape 
            xmlns:android="http://schemas.android.com/apk/res/android" >
            <corners android:radius="0dp"/>
        </shape>
    

    使用的图片

    gray_back.jpg

    gray_front.jpg

    red_front.jpg

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 2017-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多