我在滚动视图中有一个相对布局,然后我使用以下代码创建了一个新视图:
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
}
@Override
public void onDraw(Canvas canvas) {
paint.setColor(Color.BLACK);
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(5, 5, 140, 140, paint);
}
}
然后我尝试使用 layout.addView(DrawView) 将新视图添加到相对布局中,因此它可以与其余内容一起滚动,但不起作用,没有任何显示..
我错过了什么吗?
编辑:
DrawView formas;
GifMovieView gif;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final RelativeLayout layout = new RelativeLayout(this);
final ScrollView scrollView = new ScrollView(this);
//gif = new GifMovieView(this, t_img);
formas = new DrawView(this);
layout.addView(formas);
scrollView.addView(layout);
this.setContentView(scrollView);
inicializar();
load(layout);
}