开发中遇到如题的需求找了一些方法,发现一起移动都会有偏差,于是就自己修改了下代码,可以实现无偏差一起滑动,代码如下:
1.布局代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@color/screen_bg"    android:orientation="vertical">     <TextView       android:id="@+id/tv_quota"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:textColor="#FF233845"       android:textSize="15sp"/>      <SeekBar          android:id="@+id/sb_quota"          style="@style/mprogress_horizontal"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:thumb="@mipmap/bulegress_button" />LinearLayout>

2.activity代码

 private SeekBar sb_quota; private TextView tv_quota;     tv_quota = (TextView) rootView.findViewById(R.id.tv_quota);     sb_quota = (SeekBar) rootView.findViewById(R.id.sb_quota);     sb_quota.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {            @Override            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {                tv_quota.setText("¥" + progress);                int quotaWidth = tv_quota.getWidth();                final Drawable thumb = seekBar.getThumb();                 //获取thumb的位置                final Rect bounds = thumb.getBounds();                //thumb的位置为canvas的相对位置,减去thumb和textview的差值的一半,另外还要加上SeekBar相对屏幕距离                tv_quota.setX((thumb.getIntrinsicWidth() - quotaWidth) / 2                        + bounds.left + seekBar.getX());            }            @Override            public void onStartTrackingTouch(SeekBar seekBar) {            }            @Override            public void onStopTrackingTouch(SeekBar seekBar) {            }        });

更多相关文章

  1. Android面向切面编程(AOP)浅析
  2. 【Android病毒分析报告】 - Extension
  3. Eclipse中如何关联android sdk源码
  4. [置顶] MTK Android(安卓)编译小结
  5. AspectJ in Android(安卓)(一),AspectJ 基础概念
  6. android常见对话框(AlertDialog)总结 一
  7. Android(安卓)TabViewActivity中overridePendingTransition失效
  8. Android(安卓)打造万能适配器
  9. Android(安卓)Glide Error:Failed to resolve: com.github.bumpt

随机推荐

  1. 图文列表与课程表
  2. 图文列表和表格(商品表)
  3. 表格/图片/链接/列表
  4. 图文列表和行程列表
  5. 第一课 20220316
  6. 使用table做一个简易的课程表
  7. HTML中课程表制作
  8. Android(安卓)之两点触摸技术
  9. Android开发插件Eclipse ADT
  10. Android(安卓)fastboot