
大家好,
我试图用工具提示自定义android搜索栏,就像给定的图像一样.有没有办法用拇指在搜索栏中添加textview.或任何其他想法
谢谢
Bor*_*ora 17
我们可以通过获得拇指的界限来做到这一点.并在seekbar的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);
}
Run Code Online (Sandbox Code Playgroud)
对Bora(最佳)答案的一些优化:
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
mDistance.setText("" + AppConstants.getDistance() + " miles");
float x = seekBarX
+ mSeekBar.getThumb().getBounds().left
- toolTipTextView.getWidth()/2
+ seekBarLayoutParams.leftMargin;
mDistance.setX(x);
}
Run Code Online (Sandbox Code Playgroud)
并声明:
private RelativeLayout.LayoutParams seekBarLayoutParams;
seekBarLayoutParams = (RelativeLayout.LayoutParams) seekbar.getLayoutParams();
//or `LinearLayout` if you're using `LinearLayout`.
private float seekBarX;
int[] location = new int[2];
seekBarX = location[0];
Run Code Online (Sandbox Code Playgroud)
即使您SeekBar有余量,它也恰好位于拇指中间。
虽然,它不处理Y位置。为了解决这个问题,如果您SeekBar有一个marginTop,请将其删除,然后将其添加marginBottom到其上方的元素中(以xml格式)。
| 归档时间: |
|
| 查看次数: |
5514 次 |
| 最近记录: |