自定义拖动条应用举例:

关于监听: 
bright_sk.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                bright_tv_thumb.setText(seekBar.getProgress()+50 + "%");
                int quotaWidth = bright_tv_thumb.getWidth();
                final Drawable thumb = seekBar.getThumb();
                final Rect bounds = thumb.getBounds();
                bright_tv_thumb.setX((thumb.getIntrinsicWidth() - quotaWidth) / 2 + bounds.left + seekBar.getX());
                bright_tv_thumb.invalidate();
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                int num = seekBar.getProgress();
            }
        });

关于滑块中显示数字的layout写法:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="788px"
    android:layout_height="72px"
    android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="788px"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/shape_button_bg">

            <ImageView
                android:id="@+id/bright_iv_less"
                android:layout_width="56px"
                android:layout_height="56px"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20px"
                android:background="@mipmap/charge_limit_less"
                android:stateListAnimator="@null" />

            <TextView
                android:layout_toRightOf="@id/bright_iv_less"
                android:layout_marginStart="12px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:text="50%"
                android:textColor="@android:color/white"
                android:textSize="@dimen/settings_textsize_28" />

            <ImageView
                android:id="@+id/bright_iv_more"
                android:layout_width="56px"
                android:layout_height="56px"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20px"
                android:background="@mipmap/charge_limit_more"
                android:stateListAnimator="@null" />

            <TextView
                android:layout_toLeftOf="@id/bright_iv_more"
                android:layout_marginEnd="12px"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:text="100%"
                android:textColor="@android:color/white"
                android:textSize="@dimen/settings_textsize_28" />
        </RelativeLayout>

        <TextView
            android:layout_marginStart="76px"
            android:layout_marginEnd="76px"
            android:id="@+id/bright_tv_thumb"
            android:layout_width="201px"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:text="50%"
            android:textColor="@android:color/white"
            android:background="@drawable/shape_button_blue"
            android:textSize="@dimen/settings_textsize_28" />

        <SeekBar
            android:id="@+id/bright_sk"
            android:layout_marginStart="76px"
            android:layout_marginEnd="76px"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#00000000"
            android:max="50"
            android:maxHeight="72px"
            android:minHeight="72px"
            android:paddingStart="0dp"
            android:paddingEnd="0dp"
            android:progress="0"
            android:progressDrawable="@drawable/seekbar_charge"
            android:splitTrack="false"
            android:thumb="@drawable/bar_charge"
            android:thumbOffset="0dp" />
    </RelativeLayout>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值