I am running android 1.5
here is my code (nothing more needed to see my example, just paste in your main)
- Code: Select all
package test.test;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Generation of the ViewGroup
Button button = new Button(this);
button.setText("salut");
LinearLayout layout1 = new LinearLayout(this);
LinearLayout layout2 = new LinearLayout(this);
LinearLayout layout3 = new LinearLayout(this);
layout1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layout1.setOrientation(LinearLayout.VERTICAL);
layout1.setBackgroundColor(Color.YELLOW);
layout1.addView(button);
layout2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layout2.setOrientation(LinearLayout.VERTICAL);
layout2.setBackgroundColor(Color.RED);
layout3.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout3.setOrientation(LinearLayout.VERTICAL);
layout3.setBackgroundColor(Color.CYAN);
layout3.addView(layout1);
layout3.addView(layout2);
//we'll call it cardview
ViewGroup cardview = layout3;
//We build a bitmap called originalImage
cardview.layout(0, 0, 150, 183);
cardview.setDrawingCacheEnabled(true);
cardview.buildDrawingCache();
setContentView(cardview);
Bitmap originalImage = cardview.getDrawingCache();
//Then we try to display it
ImageView imview = new ImageView(this);
imview.setImageBitmap(originalImage);
// only the backgroung is displayed
setContentView(imview);
//If we display it normally, it works
//setContentView(cardview);
}
}

if some can upload the full project for an import in eclipse that will be fine 
