1
一个LinearLayout中我有一个名为面板这样的类:借鉴SurfaceView
public class Test extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Panel(this));
...
}
class Panel extends SurfaceView implements SurfaceHolder.Callback {
private LinearLayout layout;
public Panel(Context context) {
super(context);
layout = //get layout resource in layouts folder
}
public void onDraw(Canvas canvas) {
//I want to draw my xml layout
layout.draw(canvas);
}
}
我曾尝试使用LayoutInflater为了得到我的布局:
LayoutInflater inflater = LayoutInflater.from(context);
layout = new LinearLayout(getApplicationContext());
inflater.inflate(R.layout.mylayout, layout);
...但我不能看到屏幕上的任何东西,只有一个黑色的背景:S
的一点是,我想先画一个布局在屏幕的,然后我想动画这个布局为了显示它。问题是我不能在屏幕上绘制任何东西,因为当我将元素带到屏幕上时没有显示。所以我必须使用SurfaceView,就像在这篇文章中评论的一样:http://stackoverflow.com/questions/2554871/android-how-to-position-view-off-screen,但我无法做到这一点。 – user1116714 2011-12-27 13:19:29