I've tried a few things, but I couldn't solve them.
does anyone know why this happens?
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="@drawable/seeker" />
Custom Class
public class CustomSeeker extends LinearLayout {
private SeekBar sb_quota;
private TextView tv_quota;
private Context mContext;
public CustomSeeker(Context context) {
super(context);
this.mContext = context;
init();
}
public CustomSeeker(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
init();
}
private void init() {
inflate(mContext, R.layout.mdnslider, this);
tv_quota = findViewById(R.id.tv_quota);
sb_quota = findViewById(R.id.sb_quota);
sb_quota.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int val = (progress * (seekBar.getWidth() - 2 * seekBar.getThumbOffset())) / seekBar.getMax();
tv_quota.setText("" + progress);
tv_quota.setX(seekBar.getX() + val + seekBar.getThumbOffset() / 2);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
If anyone knows how to solve it or has an idea, I will be very grateful, I have been trying to solve this for a few days.
I've tried to apply margins to textview
and seekbar
too, but no good results.
question from:
https://stackoverflow.com/questions/66053184/thumb-textview-is-not-aligned-with-the-seekbars-thumb-center 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…