如何以编程方式在 imageView 图像下添加橙色线?
如何在图像显示在图库中之前在图像下方添加橙色线?
我想标记图片,使其从其他图片中脱颖而出。
我已经测试了各种 LayoutParams 但需要建议。
请参阅大量解释如何仅在 xml 中执行此操作。
这是适配器中我的 getView
(如果有人需要,请更新工作解决方案)imageViewWithLine
是具有布尔值的自定义 imageView
决定是否应该画线
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null){
BitmapFactory.Options bf = new BitmapFactory.Options();
bf.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeFile(files.get(position).getImagePath(),bf);
ImageViewWithLine imageViewWithLine = new ImageViewWithLine(ctx, null);
BitmapDrawable b = new BitmapDrawable(getResources(),bitmap);
imageViewWithLine.setLayoutParams(new Gallery.LayoutParams(80, 70));
imageViewWithLine.setScaleType(ImageView.ScaleType.FIT_XY);
imageViewWithLine.setBackgroundResource(GalItemBg);
imageViewWithLine.setBackgroundDrawable(b);
convertView = imageViewWithLine;
}
if(files.get(position).addLine() == true){
((ImageViewWithLine)convertView).setLine(true);
}else
((ImageViewWithLine)convertView).setLine(false);
return convertView;
}
}
How do i add an orange line under the image before it's showed in the gallery?
I want to mark the picture so it sticks out from all the other.
I have tested all kinds of LayoutParams but need advice.
See loots of explanations how to do this in the xml only.
here is my getView
in the adapter
(UPDATE WITH WORKING SOLUTION IF ANYONE NEED IT)
The imageViewWithLine
is the custom imageView that has a boolean
to determent if line should be drawn or not
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null){
BitmapFactory.Options bf = new BitmapFactory.Options();
bf.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeFile(files.get(position).getImagePath(),bf);
ImageViewWithLine imageViewWithLine = new ImageViewWithLine(ctx, null);
BitmapDrawable b = new BitmapDrawable(getResources(),bitmap);
imageViewWithLine.setLayoutParams(new Gallery.LayoutParams(80, 70));
imageViewWithLine.setScaleType(ImageView.ScaleType.FIT_XY);
imageViewWithLine.setBackgroundResource(GalItemBg);
imageViewWithLine.setBackgroundDrawable(b);
convertView = imageViewWithLine;
}
if(files.get(position).addLine() == true){
((ImageViewWithLine)convertView).setLine(true);
}else
((ImageViewWithLine)convertView).setLine(false);
return convertView;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以扩展 ImageView 类并创建自定义视图。在自定义视图中,您可以覆盖 onDraw 并以这种方式绘制橙色线。
更新:
这只是一个普通按钮,底部有一个橙色条。尺寸并不准确,但它应该为您提供一个良好的起点。
You can extend the ImageView class and create a custom view. In the custom view you can override the onDraw and draw your orange line that way.
Update:
This is just a normal button, with an orange bar along the bottom of it. The dimensions aren't exact, but it should give you a good starting point.