更新时间:2023-01-27 18:28:04
如果我理解正确的话,你需要创建上面沿球体移动的实际滑块一个数值。
If I understand correctly you want to create a number value above the actual slider that moves along the orb.
一件事你可以做的是写滑块的实际图像上方的文字为合并的文字直接在球体图像的绘制文件。
One thing you can do is write a text above the actual image of the slider by "merging" the text directly onto the drawable file of the orb image.
我假设你正在使用的第一个教程你在你原来的问题提供了
I am assuming you are using the first tutorial you provided in your original question
public class CustomSeekBar extends Activity {
SeekBar mybar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_seek_bar);
mybar = (SeekBar) findViewById(R.id.seekBar1);
mybar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
//add here your implementation
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
//add here your implementation
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int value = seekBar.getProgress(); //this is the value of the progress bar (1-100)
//value = progress; //this should also work
String valueString = value + ""; //this is the string that will be put above the slider
seekBar.setThumb(writeOnDrawable(R.drawable.thumbler_small, value));
}
});
}
public BitmapDrawable writeOnDrawable(int drawableId, String text){
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.BLACK); //Change this if you want other color of text
paint.setTextSize(20); //Change this if you want bigger/smaller font
Canvas canvas = new Canvas(bm);
canvas.drawText(text, 0, bm.getHeight()/2, paint); //Change the position of the text here
return new BitmapDrawable(bm);
}
}
这需要从你的资源绘制画在它上面的一些文字,并返回新的绘制。使用 seekBar.getProgress();
从您的搜索栏所需要的价值。
This takes a drawable from your resources draws some text on top of it and returns the new drawable. Use seekBar.getProgress();
to get the value needed from your seekbar.
我建议清理codeA一点,因为现在它创建了一个新的油漆对象,每次你触摸这是非常糟糕的搜索栏时间。
您需要做更多的东西,使工作的仅当你点击宝珠虽然...
You would need to do more stuff to make it work only when you click the orb though...