将自定义 View 和 ImageView 添加到单个布局
我想将一些图像添加到应用程序的视图中。该应用程序使用自定义视图来正常工作,但我想要一些图像以及自定义视图。我尝试添加一个布局作为 contentView,其中添加了 ImageView 和自定义视图,但它没有出现在屏幕上。 任何人都可以给我一些关于这个的想法吗? 提前致谢。
代码:
MyView view;
LinearLayout ly;
LinearLayout.LayoutParams lp;
LinearLayout.LayoutParams ImageViewlp;
lp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ImageViewlp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ly=new LinearLayout(this);
sketchBoard.setBackgroundColor(0);
ImageView img=new ImageView(this);
img.setBackgroundColor(R.drawable.img);
ly.addView(img,ImageViewlp);
view=new MyView(this);
ly.addView(view);
this.addContentView(ly, lp);
编辑:
img.setBackgroundResource(R.drawable.img);
我通过将 img.setBackgroundColor(R.drawable.img);
更改为上面的内容来解决它
I want to add some images to the View of an app. The app uses a custom view for its normal working but I want some images along with the custom View. I have tried adding a Layout as the contenView in which I added the ImageView and the custom View, but its not comming to the screen.
Can any one give me some idea on this...
thanks in advance.
Code:
MyView view;
LinearLayout ly;
LinearLayout.LayoutParams lp;
LinearLayout.LayoutParams ImageViewlp;
lp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ImageViewlp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ly=new LinearLayout(this);
sketchBoard.setBackgroundColor(0);
ImageView img=new ImageView(this);
img.setBackgroundColor(R.drawable.img);
ly.addView(img,ImageViewlp);
view=new MyView(this);
ly.addView(view);
this.addContentView(ly, lp);
Edit:
img.setBackgroundResource(R.drawable.img);
I got it solved by changing img.setBackgroundColor(R.drawable.img);
with the above one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或更好的任何值的 BG 颜色
您正在这样做,但这会导致绘制 R.Drawable.img应该
,但实际上使用 imageview 的可绘制资源 并执行
You are doing this, but this result in drawing a BG color of whatever value R.Drawable.img is
should be
or better yet actually use the imageview's drawable resource and do
通过调用此
call this through