我很抱歉,如果這個問題已被其他地方回答 - 我找不到任何人在同樣的問題。不能拖動滾動視圖內的seekbar
我添加了一個SeekBar到一個嵌套在ScrollView中的RelativeLayout。但是,我無法拖動搜索欄的大拇指。我可以點擊它的路徑來改變它的值,但我不能拖動它。任何幫助,將不勝感激。
我的XML看起來像:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/containerView"
android:background="@android:color/transparent"
android:padding="0dip"
android:layout_margin="0dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="insideOverlay"
android:id="@+id/scrollView" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:fillViewport="true">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="insideInset"
android:id="@+id/horizontalScrollView" android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/scrollContainer">
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
我的Java是:
SeekBar thisElement = new SeekBar(getActivity());
thisElement.setEnabled(true);
thisElement.setLayoutParams(lp);
thisElement.setAlpha(alphaVal);
thisElement.setMinimumHeight(elementHeight);
final int min = Integer.parseInt(getJsonPropertyValue(tmpJson, "elementSliderMinimum", "0"));
int max = Integer.parseInt(getJsonPropertyValue(tmpJson, "elementSliderMaximum", "100"));
int def = Integer.parseInt(getJsonPropertyValue(tmpJson, "elementSliderDefault", "50"));
thisElement.setMax(max - min);
thisElement.setProgress(def - min);
thisElement.setTag(elementCounter);
thisElement.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
String msg = "onTouch:" + v.getClass().toString();
Log.w("ZZ",msg);
return false;
}
});
thisElement.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
String elementSliderAction = getJsonPropertyValue(tmpJson, "elementSliderAction", "");
if (elementSliderAction.equalsIgnoreCase("changeLabel")) {
int labelNumber = -1;
String elementSliderLabel = getJsonPropertyValue(tmpJson, "elementSliderLabel", "");
for (int j=0; j<childItems.size(); j++) {
BT_item tmpElement = childItems.get(j);
if (tmpElement.getItemId().equalsIgnoreCase(elementSliderLabel)) {
TextView labelToChange = (TextView)scrollContainer.findViewWithTag(j+1000);
String newVal = "" + (progress - min);
labelToChange.setText(newVal);
}
}
}
else if (elementSliderAction.equalsIgnoreCase("saveToPref")) {
String elementSliderPrefName = getJsonPropertyValue(tmpJson, "elementSliderPrefName", "");
String newVal = "" + (progress - min);
setPrefString(elementSliderPrefName, newVal);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
scrollContainer.addView(thisElement);
我懷疑這是因爲我的XML文件的結構方式,但我不知道什麼是正確的解決方案是。我偶爾可以拖延,但只能反覆嘗試。此外,OnTouchListener正確地將其標識爲當我嘗試拖動時正在觸摸的SeekBar。
爲什麼向下票呢? – user3654985