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) {
        super.onCreate(savedInstanceState);

        mCtrl = new MyCtrl(this);
        setContentView(mCtrl);
    }
}

public class MyCtrl extends ScrollView {

    public MyCtrl (Context context) {
        super(context);
        setFocusable(true);

        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,
Bitmap.Config.ARGB_4444);
        ImageView iv = new ImageView(getContext());
        iv.setLayoutParams( new LinearLayout.LayoutParams(width, height) );
        iv.setImageBitmap(bmp);
        iv.setScaleType(ImageView.ScaleType.CENTER);
        addView(iv);
    }
}


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

Your help is highly appreciated.

Cheers,
Frank

-- 



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 manage several screens

Hello,

I got a Device with several screens.
How to manage these several screens with Android Framework?

Thanks
Rob

--~--~---------~--~----~------------~-------~--~----~

2. upgrade issues and other market problems for developers

We think we have figured out a problem with copy protection and how it
relates to upgrades.

**THE EXACT SAME CODE GOING FROM A VERSION THAT IS COPY PROTECTED TO A
VERSION THAT IS UN-PROTECTED WILL NOT WORK**

We hope to save developers the headache and one-star ratings we have
received due to this issue (as if the one-stars related to the
inability to download!).

Google really needs to think about developers and attempt to remove
ratings and comments that are clearly related to their bugs not ours.
Otherwise, I don't think they are taking care of developers or users.


--~--~---------~--~----~------------~-------~--~----~

3. Taking Screen Shots

4. Animation Styles

5. Launcher Permissions

6. How can I programically adjust an InsetDrawable 's padding

7. Wiki for Android development