欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義雙向滑動控件

 更新時(shí)間:2022年04月19日 18:09:51   作者:抱著回憶旅行  
這篇文章主要為大家詳細(xì)介紹了Android自定義雙向滑動控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義雙向滑動控件的具體代碼,供大家參考,具體內(nèi)容如下

先看一下效果圖

1.SeekBarPressure工具類

public class SeekBarPressure extends View {
? ? private static final String TAG = "SeekBarPressure";
? ? private static final int CLICK_ON_LOW = 1; ? ? ?//點(diǎn)擊在前滑塊上
? ? private static final int CLICK_ON_HIGH = 2; ? ? //點(diǎn)擊在后滑塊上
? ? private static final int CLICK_IN_LOW_AREA = 3;
? ? private static final int CLICK_IN_HIGH_AREA = 4;
? ? private static final int CLICK_OUT_AREA = 5;
? ? private static final int CLICK_INVAILD = 0;
? ? /*
? ? ?* private static final int[] PRESSED_STATE_SET = {
? ? ?* android.R.attr.state_focused, android.R.attr.state_pressed,
? ? ?* android.R.attr.state_selected, android.R.attr.state_window_focused, };
? ? ?*/
? ? private static final int[] STATE_NORMAL = {};
? ? private static final int[] STATE_PRESSED = {
? ? ? ? ? ? android.R.attr.state_pressed, android.R.attr.state_window_focused,
? ? };
? ? private Drawable hasScrollBarBg; ? ? ? ?//滑動條滑動后背景圖
? ? private Drawable notScrollBarBg; ? ? ? ?//滑動條未滑動背景圖
? ? private Drawable mThumbLow; ? ? ? ? //前滑塊
? ? private Drawable mThumbHigh; ? ? ? ?//后滑塊
?
? ? private int mScollBarWidth; ? ? //控件寬度=滑動條寬度+滑動塊寬度
? ? private int mScollBarHeight; ? ?//滑動條高度
?
? ? private int mThumbWidth; ? ? ? ?//滑動塊寬度
? ? private int mThumbHeight; ? ? ? //滑動塊高度
?
? ? private double mOffsetLow = 0; ? ? //前滑塊中心坐標(biāo)
? ? private double mOffsetHigh = 0; ? ?//后滑塊中心坐標(biāo)
? ? private int mDistance = 0; ? ? ?//總刻度是固定距離 兩邊各去掉半個(gè)滑塊距離
?
? ? private int mThumbMarginTop = 30; ? //滑動塊頂部距離上邊框距離,也就是距離字體頂部的距離
?
? ? private int mFlag = CLICK_INVAILD;
? ? private OnSeekBarChangeListener mBarChangeListener;
?
?
? ? private double defaultScreenLow = 0; ? ?//默認(rèn)前滑塊位置百分比
? ? private double defaultScreenHigh = 100; ?//默認(rèn)后滑塊位置百分比
?
? ? private boolean isEdit = false; ? ? //輸入框是否正在輸入
?
? ? public SeekBarPressure(Context context) {
? ? ? ? this(context, null);
? ? }
?
? ? public SeekBarPressure(Context context, AttributeSet attrs) {
? ? ? ? this(context, attrs, 0);
? ? }
?
? ? public SeekBarPressure(Context context, AttributeSet attrs, int defStyle) {
? ? ? ? super(context, attrs, defStyle);
// ? ? ? ?this.setBackgroundColor(Color.BLACK);
?
? ? ? ? Resources resources = getResources();
? ? ? ? notScrollBarBg = resources.getDrawable(R.color.red);
? ? ? ? hasScrollBarBg = resources.getDrawable(R.color.blue);
? ? ? ? mThumbLow = resources.getDrawable(R.drawable.blue);
? ? ? ? mThumbHigh = resources.getDrawable(R.drawable.red);
?
? ? ? ? mThumbLow.setState(STATE_NORMAL);
? ? ? ? mThumbHigh.setState(STATE_NORMAL);
?
? ? ? ? mScollBarWidth = notScrollBarBg.getIntrinsicWidth();
? ? ? ? mScollBarHeight = notScrollBarBg.getIntrinsicHeight();
?
? ? ? ? mThumbWidth = mThumbLow.getIntrinsicWidth();
? ? ? ? mThumbHeight = mThumbLow.getIntrinsicHeight();
?
? ? }
?
? ? //默認(rèn)執(zhí)行,計(jì)算view的寬高,在onDraw()之前
? ? protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
? ? ? ? int width = measureWidth(widthMeasureSpec);
// ? ? ? ?int height = measureHeight(heightMeasureSpec);
? ? ? ? mScollBarWidth = width;
? ? ? ? mOffsetHigh = width - mThumbWidth / 2;
? ? ? ? mOffsetLow = mThumbWidth / 2;
? ? ? ? mDistance = width - mThumbWidth;
?
? ? ? ? mOffsetLow = formatDouble(defaultScreenLow / 100 * (mDistance ))+ mThumbWidth / 2;
? ? ? ? mOffsetHigh = formatDouble(defaultScreenHigh / 100 * (mDistance)) + mThumbWidth / 2;
? ? ? ? setMeasuredDimension(width, mThumbHeight + mThumbMarginTop+2);
? ? }
?
?
? ? private int measureWidth(int measureSpec) {
? ? ? ? int specMode = MeasureSpec.getMode(measureSpec);
? ? ? ? int specSize = MeasureSpec.getSize(measureSpec);
? ? ? ? //wrap_content
? ? ? ? if (specMode == MeasureSpec.AT_MOST) {
? ? ? ? }
? ? ? ? //fill_parent或者精確值
? ? ? ? else if (specMode == MeasureSpec.EXACTLY) {
? ? ? ? }
?
? ? ? ? return specSize;
? ? }
?
? ? private int measureHeight(int measureSpec) {
? ? ? ? int specMode = MeasureSpec.getMode(measureSpec);
? ? ? ? int specSize = MeasureSpec.getSize(measureSpec);
? ? ? ? int defaultHeight = 100;
? ? ? ? //wrap_content
? ? ? ? if (specMode == MeasureSpec.AT_MOST) {
? ? ? ? }
? ? ? ? //fill_parent或者精確值
? ? ? ? else if (specMode == MeasureSpec.EXACTLY) {
? ? ? ? ? ? defaultHeight = specSize;
? ? ? ? }
?
? ? ? ? return defaultHeight;
? ? }
?
? ? protected void onLayout(boolean changed, int l, int t, int r, int b) {
? ? ? ? super.onLayout(changed, l, t, r, b);
? ? }
?
? ? protected void onDraw(Canvas canvas) {
? ? ? ? super.onDraw(canvas);
?
// ? ? ? ?Paint text_Paint = new Paint();
// ? ? ? ?text_Paint.setTextAlign(Paint.Align.CENTER);
// ? ? ? ?text_Paint.setColor(Color.RED);
// ? ? ? ?text_Paint.setTextSize(50);
?
? ? ? ? int aaa = mThumbMarginTop + mThumbHeight / 2 - mScollBarHeight / 2;
? ? ? ? int bbb = aaa + mScollBarHeight;
?
? ? ? ? //白色,不會動
? ? ? ? notScrollBarBg.setBounds(mThumbWidth / 2, aaa, mScollBarWidth - mThumbWidth / 2, bbb);
? ? ? ? notScrollBarBg.draw(canvas);
?
? ? ? ? //藍(lán)色,中間部分會動
? ? ? ? hasScrollBarBg.setBounds((int)mOffsetLow, aaa, (int)mOffsetHigh, bbb);
? ? ? ? hasScrollBarBg.draw(canvas);
?
? ? ? ? //前滑塊
? ? ? ? mThumbLow.setBounds((int)(mOffsetLow - mThumbWidth / 2), mThumbMarginTop, (int)(mOffsetLow + mThumbWidth / 2), mThumbHeight + mThumbMarginTop);
? ? ? ? mThumbLow.draw(canvas);
?
? ? ? ? //后滑塊
? ? ? ? mThumbHigh.setBounds((int)(mOffsetHigh - mThumbWidth / 2), mThumbMarginTop, (int)(mOffsetHigh + mThumbWidth / 2), mThumbHeight + mThumbMarginTop);
? ? ? ? mThumbHigh.draw(canvas);
?
? ? ? ? double progressLow = formatDouble((mOffsetLow - mThumbWidth / 2) * 100 / mDistance);
? ? ? ? double progressHigh = formatDouble((mOffsetHigh - mThumbWidth / 2) * 100 / mDistance);
// ? ? ? ? ? ?Log.d(TAG, "onDraw-->mOffsetLow: " + mOffsetLow + " ?mOffsetHigh: " + mOffsetHigh ? + " ?progressLow: " + progressLow + " ?progressHigh: " + progressHigh);
? ? ? ?// canvas.drawText((int) progressLow + "", (int)mOffsetLow - 2 - 2, 15, text_Paint);
? ? ? ?// canvas.drawText((int) progressHigh + "", (int)mOffsetHigh - 2, 15, text_Paint);
?
? ? ? ? if (mBarChangeListener != null) {
? ? ? ? ? ? if (!isEdit) {
? ? ? ? ? ? ? ? mBarChangeListener.onProgressChanged(this, progressLow, progressHigh);
? ? ? ? ? ? }
?
? ? ? ? }
? ? }
?
? ? @Override
? ? public boolean onTouchEvent(MotionEvent e) {
? ? ? ? //按下
? ? ? ? if (e.getAction() == MotionEvent.ACTION_DOWN) {
? ? ? ? ? ? if (mBarChangeListener != null) {
? ? ? ? ? ? ? ? mBarChangeListener.onProgressBefore();
? ? ? ? ? ? ? ? isEdit = false;
? ? ? ? ? ? }
? ? ? ? ? ? mFlag = getAreaFlag(e);
// ? ? ? ? ? ?Log.d(TAG, "e.getX: " + e.getX() + "mFlag: " + mFlag);
// ? ? ? ? ? ?Log.d("ACTION_DOWN", "------------------");
? ? ? ? ? ? if (mFlag == CLICK_ON_LOW) {
? ? ? ? ? ? ? ? mThumbLow.setState(STATE_PRESSED);
? ? ? ? ? ? } else if (mFlag == CLICK_ON_HIGH) {
? ? ? ? ? ? ? ? mThumbHigh.setState(STATE_PRESSED);
? ? ? ? ? ? } else if (mFlag == CLICK_IN_LOW_AREA) {
? ? ? ? ? ? ? ? mThumbLow.setState(STATE_PRESSED);
? ? ? ? ? ? ? ? //如果點(diǎn)擊0-mThumbWidth/2坐標(biāo)
? ? ? ? ? ? ? ? if (e.getX() < 0 || e.getX() <= mThumbWidth/2) {
? ? ? ? ? ? ? ? ? ? mOffsetLow = mThumbWidth/2;
? ? ? ? ? ? ? ? } else if (e.getX() > mScollBarWidth - mThumbWidth/2) {
// ? ? ? ? ? ? ? ? ? ?mOffsetLow = mDistance - mDuration;
? ? ? ? ? ? ? ? ? ? mOffsetLow = mThumbWidth/2 + mDistance;
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? mOffsetLow = formatDouble(e.getX());
// ? ? ? ? ? ? ? ? ? ?if (mOffsetHigh<= mOffsetLow) {
// ? ? ? ? ? ? ? ? ? ? ? ?mOffsetHigh = (mOffsetLow + mDuration <= mDistance) ? (mOffsetLow + mDuration)
// ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?: mDistance;
// ? ? ? ? ? ? ? ? ? ? ? ?mOffsetLow = mOffsetHigh - mDuration;
// ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else if (mFlag == CLICK_IN_HIGH_AREA) {
? ? ? ? ? ? ? ? mThumbHigh.setState(STATE_PRESSED);
// ? ? ? ? ? ? ? ?if (e.getX() < mDuration) {
// ? ? ? ? ? ? ? ? ? ?mOffsetHigh = mDuration;
// ? ? ? ? ? ? ? ? ? ?mOffsetLow = mOffsetHigh - mDuration;
// ? ? ? ? ? ? ? ?} else if (e.getX() >= mScollBarWidth - mThumbWidth/2) {
// ? ? ? ? ? ? ? ? ? ?mOffsetHigh = mDistance + mThumbWidth/2;
? ? ? ? ? ? ? ? if(e.getX() >= mScollBarWidth - mThumbWidth/2) {
? ? ? ? ? ? ? ? ? ? mOffsetHigh = mDistance + mThumbWidth/2;
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? mOffsetHigh = formatDouble(e.getX());
// ? ? ? ? ? ? ? ? ? ?if (mOffsetHigh <= mOffsetLow) {
// ? ? ? ? ? ? ? ? ? ? ? ?mOffsetLow = (mOffsetHigh - mDuration >= 0) ? (mOffsetHigh - mDuration) : 0;
// ? ? ? ? ? ? ? ? ? ? ? ?mOffsetHigh = mOffsetLow + mDuration;
// ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //設(shè)置進(jìn)度條
? ? ? ? ? ? refresh();
?
? ? ? ? ? ? //移動move
? ? ? ? } else if (e.getAction() == MotionEvent.ACTION_MOVE) {
// ? ? ? ? ? ?Log.d("ACTION_MOVE", "------------------");
? ? ? ? ? ? if (mFlag == CLICK_ON_LOW) {
? ? ? ? ? ? ? ? if (e.getX() < 0 || e.getX() <= mThumbWidth/2) {
? ? ? ? ? ? ? ? ? ? mOffsetLow = mThumbWidth/2;
? ? ? ? ? ? ? ? } else if (e.getX() >= mScollBarWidth - mThumbWidth/2) {
? ? ? ? ? ? ? ? ? ? mOffsetLow = mThumbWidth/2 + mDistance;
? ? ? ? ? ? ? ? ? ? mOffsetHigh = mOffsetLow;
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? mOffsetLow = formatDouble(e.getX());
? ? ? ? ? ? ? ? ? ? if (mOffsetHigh - mOffsetLow <= 0) {
? ? ? ? ? ? ? ? ? ? ? ? mOffsetHigh = (mOffsetLow <= mDistance+mThumbWidth/2) ? (mOffsetLow) : (mDistance+mThumbWidth/2);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else if (mFlag == CLICK_ON_HIGH) {
? ? ? ? ? ? ? ? if (e.getX() < ?mThumbWidth/2) {
? ? ? ? ? ? ? ? ? ? mOffsetHigh = mThumbWidth/2;
? ? ? ? ? ? ? ? ? ? mOffsetLow = mThumbWidth/2;
? ? ? ? ? ? ? ? } else if (e.getX() > mScollBarWidth - mThumbWidth/2) {
? ? ? ? ? ? ? ? ? ? mOffsetHigh = mThumbWidth/2 + mDistance;
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? mOffsetHigh = formatDouble(e.getX());
? ? ? ? ? ? ? ? ? ? if (mOffsetHigh - mOffsetLow <= 0) {
? ? ? ? ? ? ? ? ? ? ? ? mOffsetLow = (mOffsetHigh >= mThumbWidth/2) ? (mOffsetHigh) : mThumbWidth/2;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //設(shè)置進(jìn)度條
? ? ? ? ? ? refresh();
? ? ? ? ? ? //抬起
? ? ? ? } else if (e.getAction() == MotionEvent.ACTION_UP) {
// ? ? ? ? ? ?Log.d("ACTION_UP", "------------------");
? ? ? ? ? ? mThumbLow.setState(STATE_NORMAL);
? ? ? ? ? ? mThumbHigh.setState(STATE_NORMAL);
?
? ? ? ? ? ? if (mBarChangeListener != null) {
? ? ? ? ? ? ? ? mBarChangeListener.onProgressAfter();
? ? ? ? ? ? }
? ? ? ? ? ? //這兩個(gè)for循環(huán) 是用來自動對齊刻度的,注釋后,就可以自由滑動到任意位置
// ? ? ? ? ? ?for (int i = 0; i < money.length; i++) {
// ? ? ? ? ? ? ? ? if(Math.abs(mOffsetLow-i* ((mScollBarWidth-mThumbWidth)/ (money.length-1)))<=(mScollBarWidth-mThumbWidth)/(money.length-1)/2){
// ? ? ? ? ? ? ? ? ? ? mprogressLow=i;
// ? ? ? ? ? ? ? ? ? ? mOffsetLow =i* ((mScollBarWidth-mThumbWidth)/(money.length-1));
// ? ? ? ? ? ? ? ? ? ? invalidate();
// ? ? ? ? ? ? ? ? ? ? break;
// ? ? ? ? ? ? ? ?}
// ? ? ? ? ? ?}
//
// ? ? ? ? ? ?for (int i = 0; i < money.length; i++) {
// ? ? ? ? ? ? ? ? ?if(Math.abs(mOffsetHigh-i* ((mScollBarWidth-mThumbWidth)/(money.length-1) ))<(mScollBarWidth-mThumbWidth)/(money.length-1)/2){
// ? ? ? ? ? ? ? ? ? ? ?mprogressHigh=i;
// ? ? ? ? ? ? ? ? ? ? ? mOffsetHigh =i* ((mScollBarWidth-mThumbWidth)/(money.length-1));
// ? ? ? ? ? ? ? ? ? ? ? invalidate();
// ? ? ? ? ? ? ? ? ? ? ? break;
// ? ? ? ? ? ? ? ?}
// ? ? ? ? ? ?}
? ? ? ? }
? ? ? ? return true;
? ? }
?
? ? public int getAreaFlag(MotionEvent e) {
?
? ? ? ? int top = mThumbMarginTop;
? ? ? ? int bottom = mThumbHeight + mThumbMarginTop;
? ? ? ? if (e.getY() >= top && e.getY() <= bottom && e.getX() >= (mOffsetLow - mThumbWidth / 2) && e.getX() <= mOffsetLow + mThumbWidth / 2) {
? ? ? ? ? ? return CLICK_ON_LOW;
? ? ? ? } else if (e.getY() >= top && e.getY() <= bottom && e.getX() >= (mOffsetHigh - mThumbWidth / 2) && e.getX() <= (mOffsetHigh + mThumbWidth / 2)) {
? ? ? ? ? ? return CLICK_ON_HIGH;
? ? ? ? } else if (e.getY() >= top
? ? ? ? ? ? ? ? && e.getY() <= bottom
? ? ? ? ? ? ? ? && ((e.getX() >= 0 && e.getX() < (mOffsetLow - mThumbWidth / 2)) || ((e.getX() > (mOffsetLow + mThumbWidth / 2))
? ? ? ? ? ? ? ? && e.getX() <= ((double) mOffsetHigh + mOffsetLow) / 2))) {
? ? ? ? ? ? return CLICK_IN_LOW_AREA;
? ? ? ? } else if (e.getY() >= top
? ? ? ? ? ? ? ? && e.getY() <= bottom
? ? ? ? ? ? ? ? && (((e.getX() > ((double) mOffsetHigh + mOffsetLow) / 2) && e.getX() < (mOffsetHigh - mThumbWidth / 2)) || (e
? ? ? ? ? ? ? ? .getX() > (mOffsetHigh + mThumbWidth/2) && e.getX() <= mScollBarWidth))) {
? ? ? ? ? ? return CLICK_IN_HIGH_AREA;
? ? ? ? } else if (!(e.getX() >= 0 && e.getX() <= mScollBarWidth && e.getY() >= top && e.getY() <= bottom)) {
? ? ? ? ? ? return CLICK_OUT_AREA;
? ? ? ? } else {
? ? ? ? ? ? return CLICK_INVAILD;
? ? ? ? }
? ? }
?
? ? //更新滑塊
? ? private void refresh() {
? ? ? ? invalidate();
? ? }
?
? ? //設(shè)置前滑塊的值
? ? public void setProgressLow(double ?progressLow) {
? ? ? ? this.defaultScreenLow = progressLow;
? ? ? ? mOffsetLow = formatDouble(progressLow / 100 * (mDistance ))+ mThumbWidth / 2;
? ? ? ? isEdit = true;
? ? ? ? refresh();
? ? }
?
? ? //設(shè)置后滑塊的值
? ? public void setProgressHigh(double ?progressHigh) {
? ? ? ? this.defaultScreenHigh = progressHigh;
? ? ? ? mOffsetHigh = formatDouble(progressHigh / 100 * (mDistance)) + mThumbWidth / 2;
? ? ? ? isEdit = true;
? ? ? ? refresh();
? ? }
?
? ? public void setOnSeekBarChangeListener(OnSeekBarChangeListener mListener) {
? ? ? ? this.mBarChangeListener = mListener;
? ? }
?
? ? //回調(diào)函數(shù),在滑動時(shí)實(shí)時(shí)調(diào)用,改變輸入框的值
? ? public interface OnSeekBarChangeListener {
? ? ? ? //滑動前
? ? ? ? public void onProgressBefore();
?
? ? ? ? //滑動時(shí)
? ? ? ? public void onProgressChanged(SeekBarPressure seekBar, double progressLow,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? double progressHigh);
?
? ? ? ? //滑動后
? ? ? ? public void onProgressAfter();
? ? }
?
/* ? ?private int formatInt(double value) {
? ? ? ? BigDecimal bd = new BigDecimal(value);
? ? ? ? BigDecimal bd1 = bd.setScale(0, BigDecimal.ROUND_HALF_UP);
? ? ? ? return bd1.intValue();
? ? }*/
?
? ? public static double formatDouble(double pDouble) {
? ? ? ? BigDecimal bd = new BigDecimal(pDouble);
? ? ? ? BigDecimal bd1 = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
? ? ? ? pDouble = bd1.doubleValue();
? ? ? ? return pDouble;
? ? }
?
}

2.activity_main.xml 布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? tools:context=".MainActivity"
? ? android:background="#000"
? ? android:orientation="vertical">
?
? ? <com.yjjk.doubleseekbarsss.SeekBarPressure
? ? ? ? android:id="@+id/seekBar_tg2"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_alignParentTop="true"
? ? ? ? android:layout_marginBottom="10dp"
? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? android:layout_marginRight="10dp" />
? ? <TextView
? ? ? ? android:id="@+id/editTexts_min"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:textSize="15sp"
? ? ? ? android:textColor="#fff"></TextView>
? ? <TextView
? ? ? ? android:id="@+id/editTexts_max"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:textSize="15sp"
? ? ? ? android:textColor="#fff"></TextView>
?
?
</LinearLayout>

3.MainActivity

public class MainActivity extends AppCompatActivity {
?
? ? private boolean isScreen;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
?
? ? ? ? //id
? ? ? ? final SeekBarPressure seekBarPressures = findViewById(R.id.seekBar_tg2);
? ? ? ? final TextView editTexts_min = findViewById(R.id.editTexts_min);
? ? ? ? final TextView editTexts_max = findViewById(R.id.editTexts_max);
?
? ? ? ? seekBarPressures.setOnSeekBarChangeListener(new SeekBarPressure.OnSeekBarChangeListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onProgressBefore() {
? ? ? ? ? ? ? ? isScreen = true;
? ? ? ? ? ? }
?
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onProgressChanged(SeekBarPressure seekBar, double progressLow, double progressHigh) {
?
? ? ? ? ? ? ? ? editTexts_min.setText((int) progressLow + "");
? ? ? ? ? ? ? ? editTexts_max.setText((int) progressHigh + "");
?
? ? ? ? ? ? ? ? //獲取SharedPreferences對象
? ? ? ? ? ? ? ? SharedPreferences sharedPre=getSharedPreferences("config", MODE_PRIVATE);
?
? ? ? ? ? ? ? ? //獲取Editor對象
? ? ? ? ? ? ? ? SharedPreferences.Editor edit = sharedPre.edit();
? ? ? ? ? ? ? ? edit.clear();
?
? ? ? ? ? ? ? ? //設(shè)置參數(shù)
? ? ? ? ? ? ? ? edit.putString("progressHigh", String.valueOf(progressHigh));
? ? ? ? ? ? ? ? edit.putString("progressLow", String.valueOf(progressLow));
?
? ? ? ? ? ? ? ? //提交
? ? ? ? ? ? ? ? edit.commit();
?
? ? ? ? ? ? }
?
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onProgressAfter() {
? ? ? ? ? ? ? ? isScreen = false;
? ? ? ? ? ? }
? ? ? ? });
?
?
? ? ? ? //取值
? ? ? ? SharedPreferences sharedPre=getSharedPreferences("config",MODE_PRIVATE);
?
? ? ? ? String progressHighs = sharedPre.getString("progressHigh", "");
? ? ? ? String progressLows = sharedPre.getString("progressLow", "");
?
? ? ? ? if (progressHighs.length()!=0){
? ? ? ? ? ? seekBarPressures.setProgressHigh(Double.parseDouble(progressHighs));
? ? ? ? ? ? seekBarPressures.setProgressLow(Double.parseDouble(progressLows));
?
? ? ? ? ? ? editTexts_max.setText(progressHighs);
? ? ? ? ? ? editTexts_min.setText(progressLows);
? ? ? ? }else {
? ? ? ? ? ? seekBarPressures.setProgressLow(30);
? ? ? ? ? ? seekBarPressures.setProgressHigh(70);
?
? ? ? ? ? ? editTexts_min.setText("最小值:"+30);
? ? ? ? ? ? editTexts_max.setText("最大值:"+70);
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android studio自定義對話框效果

    Android studio自定義對話框效果

    這篇文章主要為大家詳細(xì)介紹了Android studio自定義對話框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 去掉RecycleView或者ListView上下滑動陰影的方法

    去掉RecycleView或者ListView上下滑動陰影的方法

    下面小編就為大家分享一篇去掉RecycleView或者ListView上下滑動陰影的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • Android React-Native通信數(shù)據(jù)模型分析

    Android React-Native通信數(shù)據(jù)模型分析

    這篇文章主要介紹了Android React-Native通信數(shù)據(jù)模型分析的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • android獲取屏幕的長與寬實(shí)現(xiàn)代碼(手寫)

    android獲取屏幕的長與寬實(shí)現(xiàn)代碼(手寫)

    android中獲取屏幕的長于寬,參考了網(wǎng)上有很多代碼,但結(jié)果與實(shí)際不符,如我的手機(jī)是i9000,屏幕大小是480*800px,得到的結(jié)果卻為320*533,于此問題很是疑惑,于是自己寫了幾行代碼,親測一下,效果還不錯(cuò),需要了解的朋友可以參考下
    2012-12-12
  • Android App中的多個(gè)LinearLayout嵌套布局實(shí)例解析

    Android App中的多個(gè)LinearLayout嵌套布局實(shí)例解析

    這篇文章主要介紹了Android App中的多個(gè)LinearLayout嵌套布局實(shí)例,利用線性布局來排列按鈕是安卓應(yīng)用布局中的常用做法,需要的朋友可以參考下
    2016-04-04
  • Android 雙擊Back鍵退出應(yīng)用的實(shí)現(xiàn)方法

    Android 雙擊Back鍵退出應(yīng)用的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android 雙擊Back鍵退出應(yīng)用的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,讓大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-10-10
  • Kotlin Fragment的具體使用詳解

    Kotlin Fragment的具體使用詳解

    Fragment是Android3.0后引入的一個(gè)新的API,他出現(xiàn)的初衷是為了適應(yīng)大屏幕的平板電腦, 當(dāng)然現(xiàn)在他仍然是平板APP UI設(shè)計(jì)的寵兒,而且我們普通手機(jī)開發(fā)也會加入這個(gè)Fragment, 我們可以把他看成一個(gè)小型的Activity,又稱Activity片段
    2022-10-10
  • 一篇文章弄懂Android自定義viewgroup的相關(guān)難點(diǎn)

    一篇文章弄懂Android自定義viewgroup的相關(guān)難點(diǎn)

    這篇文章主要給大家介紹了關(guān)于如何通過一篇文章弄懂Android中自定義viewgroup的一些相關(guān)難點(diǎn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06
  • 利用Flutter繪制出3D效果動畫

    利用Flutter繪制出3D效果動畫

    本文主要介紹了Flutter繪圖的Path的應(yīng)用。Flutter的Path類提供了一個(gè)三維空間的變換方法,可以實(shí)現(xiàn)路徑在三維空間的平移、旋轉(zhuǎn)等操作,從而可以實(shí)現(xiàn)3D繪制的效果,感興趣的可以了解一下
    2022-08-08
  • Android 實(shí)現(xiàn)背景圖和狀態(tài)欄融合方法

    Android 實(shí)現(xiàn)背景圖和狀態(tài)欄融合方法

    下面小編就為大家分享一篇Android 實(shí)現(xiàn)背景圖和狀態(tài)欄融合方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01

最新評論