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. How to draw an image on top of another drawable?

You have to use a LayerDrawable but it can be used only from XML (for
now.) You can also simply create your own Drawable, it's pretty easy.

Romain Guy


2. Trouble with AssetManager

I am using this code to try to access my assets:
Resources res = context.getResources();
AssetManager assMan = res.getAssets();
String assets[] = assMan.list("Models");
InputStream is = assMan.open("Models/Ship.Obj");
 ObjLoader loader = new ObjLoader(is);
mVertexBuffer = loader.getVerts();
mIndexBuffer = loader.getIndex();
catch(IOException e)
// TODO Auto-generated catch block

When I look at the value of assets it contains "Ship.obj" (see attached
image) but when I try to open the file it throws the exception.  Does anyone
have any experience with this?


3. OutOfMemoryError when switching orientation

4. How to set the max width of a spinner

5. IPhone Android & G1 Android

6. What is the difference between onOptionsItemSelected and onMenuItemSelected?

7. Question about the Android Market