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. Reading and Writing PNG Metadata

Is there a core facility to read/write PNG meteadata? In standard
Java, it's available as part of imageio but I don't see simliar
feature provided by BitmapFactory.



2. File Browsing or Customisation Activities

I'm working on a simple Android app to teach myself Android
development before I tackle something larger. It's just a small app
that allows you to change wallpaper and ringtone settings (and maybe
more). I know it's quite pointless but, as I said, it's just an
educational project.

So far, everything's working but it's using text boxes with absolute
paths for the wallpapers and ringtones. What I'm wanting to do is have
activities which allow you to select wallpapers and ringtones. A file
browser activity, maybe, or even something specifically tailorered to
my needs like a wallpaper selection activity or ringtone selection

I've been scouring the Android SDK docs but I can't see anything about
a file browsing activity (which I would assume to be a common thing)
so I'm going to assume that I'm going to have to roll my own. Is this

I've seen the RingtonePreference activity, so I can probably get away
with using that for browsing for ringtones but there doesn't appear to
be anything similar for wallpapers.

Any help will be much appreciated


3. Galaxy Spica VS HTC Legend

4. Service unable to call Java Class Methods

5. saving sharedPreferences collapse my app... for advanced dev I think

6. iPhone like Spinning Wheel

7. Google should clearly express their marketing strategy regarding Android Market