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. get the genre name with most songs from the music library

I am trying to get the genre with most songs by using the media store and 
failed to get it, as well as I can get the artist with most songs.

Any one has good idea.

Thanks.
Kyle

-- 

2. Gradient, Shadow and MaskFilter on a TextView

Hello. Im trying to customize a textview to add a gradientoverlay, a
dropshadow and a maskfilter.
There seems like i cant combine the different methods as i thought i
would.
For example when i use both gradient and shadow my shadow gets the
same color as the gradient.
Combinding dropshadow and a maskfilters renders no text at all. While
a combination of gradient overlay seems to work fine.

I have extended TextView and overriden onDraw:

    protected void onDraw(Canvas canvas) {
        TextPaint paint = getPaint();
        // paint.setShader(new LinearGradient(8f, 80f, 30f, 20f,
Color.RED,Color.WHITE,Shader.TileMode.MIRROR));
        float height = paint.getFontSpacing();
        Toast.makeText(getContext(), "h: "+height,
Toast.LENGTH_SHORT).show();

        paint.setMaskFilter(new EmbossMaskFilter(new float[] { 0,
0.3f, 0 },0.95f, 10, 0.1f));

        // paint.setShadowLayer(0.1f, 30f, 5f,
Color.parseColor("#ffffff"));

        paint.setShader(new LinearGradient(0, 0, 0, height,
                new int[]
{ GRADIENT_START,GRADIENT_MID,GRADIENT_MID,GRADIENT_END },
                new float[] {0,0.4f,0.6f,1f},
                Shader.TileMode.CLAMP));

        super.onDraw(canvas);
    }

Does these filters not work together? Is it the wrong aproach to try
to extend a textview, should i create my own View for drawing thext
with gradients, shadows and masks?

// Anders

-- 

3. Ant Emma and JUnit, integrating all three

4. Is there a Horizontal ListView?

5. How to get Temporary Mobile Subscriber Identity(TMSI) in Android

6. alsa player

7. Alarm in sleep mode