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. touchscreen: getPressure and getSize should change as finger drags, yes?

I'm not sure where else to ask this question as I've had no responses
so far in android-developers, and android-platform rejected it.

When I access the values from getPressure and getSize from the
MotionEvent objects while dragging my finger around the touchscreen, I
also get the same values as the original values in the ACTION_DOWN
MotionEvent object. That is, it's as if my finger is pressing exactly
the same throughout a finger drag, even though I'm trying to adjust
the pressure and size to see a difference. The values change from
finger press to finger press as long as I lift off then touch down
again. I'm thinking this is a bug but can't get an confirmation. My
device is a Motorola Droid. No answers from the Motorola developer's
forum either. Can anyone here help please?

- dave

unsubscribe: android-porting+unsubscr...@googlegroups.com

2. Where to start for home screen replacement app?

> Funny topic maybe, but I feel like I have a decent hold on app

There's the Home sample app in the samples that ship with the SDK. I have
no idea if it is being kept up to date, but last I knew it still worked.

Mark Murphy (a Commons Guy)
Android App Developer Books: http://commonsware.com/books.html


3. creating dynamic view, multiple a view X times

4. Where to start for home screen replacement app?

5. Save variable and ArrayList of object

6. Problems in putting android source in eclipse

7. regarding netmeter application