Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Seekbar-对齐拇指上方的值标签_Android_Seekbar_Android Seekbar_Seekbar Thumb - Fatal编程技术网

Android Seekbar-对齐拇指上方的值标签

Android Seekbar-对齐拇指上方的值标签,android,seekbar,android-seekbar,seekbar-thumb,Android,Seekbar,Android Seekbar,Seekbar Thumb,我的文本与大拇指不对齐 我的标签在屏幕上消失了。这是我的kotlin代码: val x: Int = progress * (seekBar!!.width - 2 * seekBar.thumbOffset) / seekBar.max text12.text = "$progress %" val textViewX: Int = x- text12.width / 2 val finalX = if (text12.width + textViewX > maxX){

我的文本与大拇指不对齐

我的标签在屏幕上消失了。这是我的kotlin代码:

val x: Int = progress * (seekBar!!.width - 2 * seekBar.thumbOffset) / seekBar.max
text12.text = "$progress %"
val textViewX: Int = x- text12.width / 2
val finalX =
    if (text12.width + textViewX > maxX){
        maxX - text12.width- 100
    } else textViewX +40 /*your margin*/
text12.x = if (finalX < 0) 0f /*your margin*/ else finalX.toFloat() +16
我的xml:

<SeekBar
    android:id="@+id/customSeekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="100"
    android:layout_marginTop="100dp"
    android:progress="50"
    app:layout_constraintTop_toBottomOf="@+id/tv_user_data_notsaved"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text1"
    android:text="12%"
    app:layout_constraintBottom_toTopOf="@+id/customSeekBar1"
    app:layout_constraintLeft_toLeftOf="parent"/>

下面是我的代码在我的项目中运行良好

    seekBarWithHint.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            textView.setText("" + progress + " KM");
            SmartApplication.REF_SMART_APPLICATION.writeSharedPreferences(Constants.KM, progress);
            //Get the thumb bound and get its left value
            x = seekBar.getThumb().getBounds().left;
            //set the left value to textview x value
            textView.setX(x);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
这里是xml代码

 <SeekBar
                    android:id="@+id/seekBar_luminosite"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="@dimen/_22sdp"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:layout_marginRight="@dimen/_22sdp"
                    android:maxWidth="15dp"
                    android:maxHeight="12dp"
                    android:minWidth="15dp"
                    android:minHeight="12dp"
                    android:progressDrawable="@drawable/custom_seekbar"
                    android:splitTrack="false"
                    android:thumb="@drawable/custom_thumb" />

在左边的标签是screen@Hern–niPereira应用android:layout_marginLeft或padding left来标记TextView