如何在seekbar的拇指上绘制图像和文字。滑动的图像和价值应该附上seekbar的拇指
问题描述:
我想seekbar应该有图像和文字在拇指上,而滚动图像和文字应该留在Android的seekbar的拇指请帮助我。如何在seekbar的拇指上绘制图像和文字。滑动的图像和价值应该附上seekbar的拇指
答
您可以定义一个新的拇指作为Drawable。您可以转换Drawable中的任何视图。
TextView yourView = new TextView(this);
yourView.setText("text");
yourView.setBackgroundResource(R.drawable.background_resource);
// taken from the other ticket
Bitmap snapshot = null;
Drawable drawable = null;
yourView.setDrawingCacheEnabled(true);
yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); //Quality of the snpashot
try {
snapshot = Bitmap.createBitmap(yourView.getDrawingCache(), sizes and stuff); // You can tell how to crop the snapshot and whatever in this method
drawable = new BitmapDrawable(snapshot)
} finally {
yourView.setDrawingCacheEnabled(false);
}
mySeekBar.setThumb(drawable);
我没有试过这段代码,但解决方案应该进入这个方向。
然后,可以静态创建拇指,如Drawable xml,例如分层不同的图像。无论如何,如果你想要它包含一个动态内容,你应该动态创建它,所以定期更新它。 与一个TextView创建布局,然后使用此:Create drawable from layout
感谢您的回复...但即时得到它如果可能的话再PLZ给我全班 – shripal
我更新了它,但你应该尝试,我没有测试该代码。感谢... –
,但不能正常工作,因为我想 – shripal