添加自定义视图和ImageView的单个布局 [英] Adding custom View and ImageView to a single Layout
问题描述
我想一些图像添加到应用程序的视图。该应用程序用于其正常工作的自定义视图,但我想一些图像与自定义视图一起。我曾尝试为contenView我在其中添加了ImageView的和自定义视图添加一个布局,但是它正在添加没有在屏幕上。
任何一个可以给我一些这方面的想法...
先谢谢了。
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);
编辑:
img.setBackgroundResource(R.drawable.img);
我把它改变 img.setBackgroundColor(R.drawable.img)解决;
与上面有一个
推荐答案
您正在做这件事,但这个结果在绘图的任何值R.Drawable.img是背景色
You are doing this, but this result in drawing a BG color of whatever value R.Drawable.img is
img.setBackgroundColor(R.drawable.img);
应
img.setBackgroundResource(R.drawable.img);
或更好,但实际使用的ImageView绘制资源并做
or better yet actually use the imageview's drawable resource and do
img.setImageResource(R.drawable.img);
这篇关于添加自定义视图和ImageView的单个布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!