【发布时间】:2012-10-11 02:43:33
【问题描述】:
[机器人] 我有一个包含 2 个视图的 LinearLayout,第一个是 imageView,第二个是画布。 如果我做 mLinearLayout.addView(i);然后是 MLinearLayout.addView(c);它显示了两者,但如果我以相反的方式进行(mLinearLayout.addView(c)然后是mLLinearLayout.addView(i))它只显示画布。 我想在这两个视图之间共享屏幕。有人可以帮我解决这个问题吗?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLinearLayout = new LinearLayout(this);
mLinearLayout.setBackgroundColor(0xff74AC23);
ImageView i = new ImageView(this);
View c = new DrawView(this);
i.setImageResource(R.drawable.bol_groen);
i.setAdjustViewBounds(true);
mLinearLayout.addView(i);
mLinearLayout.addView(c);
setContentView(mLinearLayout);
}
}
公共类 DrawView 扩展视图 {
private ShapeDrawable mDrawable;
public DrawView(Context context) {
super(context);
setFocusable(true); //necessary for getting the touch events
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x + width, y + height);
}
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFCCCCCC);
mDrawable.draw(canvas);
}
【问题讨论】:
-
你的意思是它只显示画布? DrawView 占据了整个屏幕,还是大小合适但 ImageView 不显示?还有你不在 xml 中这样做的原因吗?
-
请看这篇文章;希望对你有所帮助-stackoverflow.com/questions/11071258/…
标签: android