Why ImageView doesn't show up inside ScrollView

by Frank » Fri, 20 May 2011 09:34:05 GMT

Sponsored Links
 Hi All,

I have the following code. I only got a black screen without seeing
the white image.

public class Demo extends Activity {
    private MyCtrl mCtrl;
    protected void onCreate(Bundle savedInstanceState) {

        mCtrl = new MyCtrl(this);

public class MyCtrl extends ScrollView {

    public MyCtrl (Context context) {

        int width = 100;
        int height = 100;
        int size = width * height;
        int buf[] = new int[size];
        for ( int i = 0; i < size; ++i) {
                buf[i] = 0xFFFFFFFF; //white image

        Bitmap bmp = Bitmap.createBitmap(buf, width, height,
        ImageView iv = new ImageView(getContext());
        iv.setLayoutParams( new LinearLayout.LayoutParams(width, height) );

However, if I derive MyCtrl from ImageView directly, the white image
shows up.

Your help is highly appreciated.



Re: Why ImageView doesn't show up inside ScrollView

by Mark Murphy » Fri, 20 May 2011 18:04:28 GMT

 Why are you using LinearLayout.LayoutParams for a child of a
ScrollView subclass?

Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books 


Sponsored Links

Other Threads

1. how to display images of particular folder

hi all,

i want to pick image from a folder on sdcard for that i want to
display images of that folder only how can i achieve that , i am

               Intent i = new Intent(Intent.ACTION_PICK,
                intent.putExtra( MediaStore.EXTRA_MEDIA_ALBUM,
outputFileUri );
                startActivityForResult(i, SELECT_PICTURE);

but this shows all folders on sd card..,

awaiting for reply
thanks in advance


2. Global search app

I would like to write an application that replaces the dialog that
shows up when you long press the search button. How would I making it
so my app gets launched on a search button long press?


3. Paket data xl sering disconnected

4. Gmail diandroid tidak bisa tampilkan file Gif (gambar)

5. Netbook Elevo R7 - OS Android 2.0

6. Facebook Update

7. Barnacle and Oddysey