Android: Seekbar 改变表单位置

Android: Seekbar changes form position

我有一个 Seekbar,当我触摸 seekbar 并更新它的位置时,我的表单似乎会重新定位自己 "magically"。例如,如果当我滚动表单时搜索栏位于表单的顶部,并且我开始更改搜索栏的位置,则整个表单将向上滚动并将搜索栏始终置于表单的底部。

我在滚动视图中有父表单。嵌套在里面的是一个线性布局,里面有我所有的相关布局。这是相关代码。如果需要更多代码,请告诉我。

XML:

                <RelativeLayout
                android:id="@+id/Turns_Box"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/Prev_Box"
                android:layout_margin="5dp"
                >

                <TextView
                    android:id="@+id/Turns_Text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/Turns_Text"
                    android:textSize="25sp"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"
                    />

                <SeekBar
                    android:id="@+id/Turns_Value"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/Turns_Text"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"
                    android:max="25"
                    />

                <TextView
                    android:id="@+id/Turns_Value_Text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/Turns_Value"
                    android:textSize="20sp"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginBottom="10dp"
                    />

            </RelativeLayout>

JAVA:

        // Actual Turns
    SeekBar actualTurnsValue = (SeekBar)findViewById(R.id.Turns_Value);
    turnsValueText = (TextView)findViewById(R.id.Turns_Value_Text);
    turnsValueText.setFocusable(false);
    actualTurnsValue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                turnsValueText.setText(progress + 5 + "  Full Revolutions");
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            graphicAttributes.setActualTurns(Integer.toString(seekBar.getProgress() + 5));
        }
    });

请帮忙!

好吧,看来我对发生的事情留下了模糊的线索。我所有的观点都没有 "focusable" 集。因此,当我创建我的第一个滚动视图并且没有控件设置为焦点时,Android 选择第一个需要焦点的合格控件。这在我的代码中导致了一些奇怪的功能。从这里的答案中找到它:

所以我只是将我的嵌套 LinearLayout 设置为:

android:focusableInTouchMode="true"