1

I have a class called Panel like this:

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

    }
}

I have tried to use LayoutInflater in order to get my layout:

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

... but I cant see anything on the screen, only a black background :S

user1116714
  • 315
  • 2
  • 3
  • 12

1 Answers1

0

as far as I know you can't draw a linear layout inside the SurfaceView you can draw anything you want in your SurfaceView if you want to add elements to your view like buttons or something like that I recommend using the XML and putting all your elements there. Something like this:

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

and then you may set your content of your view with setContentView(R.layout.my_xml);

Raykud
  • 2,488
  • 3
  • 21
  • 41
  • The point is that I want to draw a Layout first out of the screen, and then I want to animate this layout in order to show it. The problem is that I cant draw anything out of the screen because it is not showed when I bring the element to the screen. So I have to use a SurfaceView, just as is commented in this post: http://stackoverflow.com/questions/2554871/android-how-to-position-view-off-screen, but I am not able to do it. – user1116714 Dec 27 '11 at 13:19