Android 在曲面视图上绘制线性布局

Android 在曲面视图上绘制线性布局,android,layout,surfaceview,Android,Layout,Surfaceview,我有一个叫做Panel的类,如下所示: public class Test extends Activity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); ... } class Panel extends SurfaceView implements SurfaceHold

我有一个叫做Panel的类,如下所示:

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);

    }
}
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SurfaceView android:id="@+id/mySurfaceView"
        android:layout_width="match_parent" 
        android:layout_height="match_parent"
        android:layout_weight="1">      
    </SurfaceView>
    <Button android:id="@+id/button" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_centerVertical="true" 
        android:text="myButton"/>
</LinearLayout>
我已尝试使用LayoutInflater以获得我的布局:

LayoutInflater inflater = LayoutInflater.from(context);
layout = new LinearLayout(getApplicationContext());
inflater.inflate(R.layout.mylayout, layout);

。。。但是我在屏幕上什么都看不到,只有黑色背景:S

据我所知,你不能在
SurfaceView
中绘制线性布局。如果你想在视图中添加类似按钮之类的元素,我建议使用XML并将所有元素放在那里,你可以在
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);

    }
}
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SurfaceView android:id="@+id/mySurfaceView"
        android:layout_width="match_parent" 
        android:layout_height="match_parent"
        android:layout_weight="1">      
    </SurfaceView>
    <Button android:id="@+id/button" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_centerVertical="true" 
        android:text="myButton"/>
</LinearLayout>


然后您可以使用
setContentView(R.layout.my_xml)设置视图的内容

重点是我想先从屏幕上画出一个布局,然后我想制作这个布局的动画以显示它。问题是我不能从屏幕上画出任何东西,因为当我把元素带到屏幕上时它没有显示出来。所以我必须使用SurfaceView,正如这篇文章中所评论的那样:,但我不能这样做。