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. WebView and geolocation questions

I have been attempting for a few days now to get a webview to work with a 
location based service. Every post I can find seems to say the same thing - 
create a webchromeclient and override onGeolocationShowPrompt(). 

I have gone as far as directly creating a copy of this and running it.
Code: https://gist.github.com/886546
Web page used to test: http://www.sourcerebels.com/geo/

The web page loads everything up until Geolocation supported, and then does 
Can someone at least test that code and tell me if they are having the same 


2. Change Android market signing key

I have been working on a project created by someone else. They send me
the source code with the question to make some improvements. Now all
my improvements have been implemented, and we want to upgrade the
application in the Android Market.

Since there will be more improvements in the future, I would like to
know if it's possible to migrate the app to my own account! However, I
don't want to create a "new" app, since than all users (> 250.000)
will have to download again.

Note, the original developers would like to cooperate, so they don't
have to sign all new releases...
Is it possible? Anyone has experience? Someone knows how to contact
google about this?

Thanks in advance


3. Newbie question: What is "this" in the code?

4. Extra space is coming in tabs while adding images

5. install c++ application in my android

6. I can't link tweeter to my blog

7. keeping track of time a user is actively using an android app