繁体   English   中英

我怎样才能在图框的拇指上绘制图像和文本。 滑动图像和值时,请用搜寻棒的拇指

[英]How can i draw image and text upon thumb of seekbar. while sliding image and value should be attach with the thumb of seekbar

我想要seekbar,其中拇指上应该有图像和文本,而在Android中滚动图像和文本时应保持在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);

我没有尝试这段代码,但是解决方案应该朝这个方向发展。

然后,可以静态创建Thumb,作为Drawable xml,例如对不同的图像进行分层。 无论如何,如果希望它包含动态内容,则应该动态创建它,因此要定期更新它。 使用textview创建一个布局,然后使用它: 从布局创建drawable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM