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. Stop service doesn't work

Hi,

I have one service that is running in the background and make a simple
scheduled (every 10 seconds) notification on the notification bar.
I'm trying to call the stopservice method, but the result is always
false and the service onDestroy() method is never called.

Any hint?

thanks

public class ServiceActivity extends Activity {

    /** Called when the activity is first created. */

   .....
   ....

  public void onCreate(Bundle savedInstanceState) {

       try{

        TestService.setMainActivity(this);

       }catch(Exception e){

           t.setText(e.getMessage());

       }

    }

@Override
    public void onStop() {
        super.onStop();
        Log.d("onStop:" , "stopping activity");
        Intent svc = new Intent(this,TestService.class);
                Boolean result = false;
                try {
                        result = stopService(svc);
                        Log.d("onStop:" , "stop service result: " + result);

                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }


    }

}
================================

public class TestService extends Service {

        private static Timer timer = new Timer();
        private static ServiceActivity ServAct;
        static long i=0;




        @Override
        public IBinder onBind(Intent intent) {
                return(null);
        }

        @Override
        public void onCreate() {
                super.onCreate();
                Log.d( "Servizio","onCreate" );
        }

    @Override
    public void onDestroy() {
          super.onDestroy();
          _shutdownService();

          Log.d( "Servizio","onDestroy" );
    }



    public static void setMainActivity(ServiceActivity activity) {

        ServAct = activity;

        Log.d("TestService","started!!");

                _startService();


        }

    private static void _startService() {

                  timer.scheduleAtFixedRate(

                      new TimerTask() {

                        public void run() {

                                update();

                        }

                      },

                      0,

                      10000);

                }

    public static void update(){

        i++;

        ServAct.setNotification("Test Service " + i, "Value = " + i);


        }

    private void _shutdownService() {
          if (timer != null) timer.cancel();
          Log.d(getClass().getSimpleName(), "Timer stopped!!!");
        }



}




-- 

2. Flash LED with screen on?

I have an app that displays an LED notification on certain events.
 Currently, the notification only plays when the screen is sleeping/off
which i know is expected behavior.

My question is: Is there any way to force the LED to flash even if the
screen is lit at the time?

-- 
//Nick Richardson
//richardson.n...@gmail.com

-- 

3. Rapid Android Development with AML, looking for feedback

4. Drawing Google Maps in a Surfaceview

5. main screen and dialog box on that screen

6. Speech to text not working behind corporate firewall

7. Detecting button type of front nav keys