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. ARCHOS 5 Android tablet and getExternalStorageDirectory()

I think that was me...

Thanks Mark.

So I guess this means we have the same problems in terms of a very
limited storage space for apps?

i.e. Should large data files be downloaded to /storage?


2. Samsung Moment (SPH-M900) - Application crashing

I do remember seeing a post yesterday where someone that was using
AudioRecord found out that on the Moment it only supports 8Khz sample
rate, and he had not correctly checked for error codes in the
getMinBufferSize call to AudioRecord. Are  you perhaps using that API?



3. How to read resource based on the current theme

4. how i can use Settings.Secure.ADB_ENABLED and Settings.Secure.USB_MASS_STORAGE_ENABLED?

5. Absolutely Infuriating

6. Map Application works in 1.5 but not working in 2.0

7. random problem