关于监听:
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>