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. Hide Clock

What are you talking about? That '19:05' is a clock!! and that's a big ass
clock!!! xD





> 

2. Tanya Aplikasi Standar Must Have di Samsung Spica ?

Assalamualaikum, Malam
Langsung aja ya..Spicaku dah dateng (tadi siang habis jumatan),warna putih seneng banget sih ngeliatnya, reviewnya persis sama yang om dan tante jawab dalam postingan saya sebelumnya, udah official upgrade android 2.1 update 1.gps, ifi, blueetooth, youtube berfungsi dengan baik.Dengan telkomflash unlimited dah dapet signal 3G dan HSDPA. doakan ya semoga betah saya pakai android ini :-) tapi bingung banget ada beberapa pertanyaan nih untuk RR : - Bagaimana caranya ngecek kalo android saya udah diroot ? - Hanya ada aplikasi market (isinya software free) bingung milihnya :-( , menurut pengalaman RR, aplikasi standar apa saja yang harus diinstall di android saya ? - Kalau aplikasi black market itu apaan sih ? bagaimana caranya mendapatkan aplikasi black market tersebut ? tolong jelasin ya. - Ada yang punya silicone case untuk spica, prefer warna putih (japri aja) - Bagaimana caranya aplikasi2 yang ingin saya install nantinya di install di sdcard ? Saya cuman install hencent sms, aplikasi yang bagus. oh..ya..racun apa saja aq terima nih, asal dengan penjelasan yang lengkap :-D Makasih atas waktu dan jawabannya Best regards, Afiadi -- "Indonesian Android Community [id-android]"

3. Loaded time zone names infinite loop issue

4. Re[2]: WTS : tablet Apad Android7 - ipAd killer

5. EditText is unuseful on widget

6. Uninstall aplikasi private

7. Tether di spica