我在我的應用程序中有一個SeekBar,我希望它的行爲使得當用戶拖動'thumb'時,一個Popup出現在拇指上方(並且遵循拇指拖動),並且彈出窗口顯示SeekBar的相應位置(或位置可能表示的任何其他文本)。在Android中創建一個SeekBar位置popup
有什麼建議嗎?
我在我的應用程序中有一個SeekBar,我希望它的行爲使得當用戶拖動'thumb'時,一個Popup出現在拇指上方(並且遵循拇指拖動),並且彈出窗口顯示SeekBar的相應位置(或位置可能表示的任何其他文本)。在Android中創建一個SeekBar位置popup
有什麼建議嗎?
我找到這個彈出後面的搜索欄的解決方案是把textview放在相對佈局正上方搜索條。然後,在搜索條的onProgressChange,設置TextView的左邊緣從而用
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(widht, height)
params.setLeftMargin(margin)
的偉大工程,與一些調整!
歡呼聲
拇指是可繪製的,所以一個解決方案可以是將拇指設置爲包含拇指和彈出文本的繪圖。這意味着您需要爲滑塊上的每個可能值繪製一個可繪製/圖標,並在每次更改值時更新它。環顧四周,我發現這一點,這表明其他人已經走過了這樣的方式,當他們需要在他們的可繪製文本:Convert String to Drawable
這一定很晚但是我這樣做。
通過獲取拇指的範圍。和progressChanged設置TextView中的x在搜索條
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mDistance.setText("" + AppConstants.getDistance() + " miles");
//Get the thumb bound and get its left value
int x = mSeekBar.getThumb().getBounds().left;
//set the left value to textview x value
mDistance.setX(x);
}
看看這個blog
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.ABOVE, seekBar.getId());
Rect thumbRect = bar.getSeekBarThumb().getBounds();
p.setMargins(
thumbRect.centerX(),0, 0, 0);
textView.setLayoutParams(p);
textView.setText(String.valueOf(progress));
}
});
}
}
你是如何計算保證金的? – JRaymond
有沒有setLeftMargin方法 – GOLDEE
你能深入解釋一下,它的工作原理如何? – shripal