Smooth transition of layout size using streams

I am changing the height and width of the layout programmatically. This changes, but the problem is that they don't change smoothly since I am using a stream. I want the layout size (height and width) to have a smooth transition. this is my code:

 final Handler handler = new Handler();
 Runnable runable = new Runnable() 
 {
     @Override
     public void run() {
         try {
             Log.d("This is working", "This is working");
             handler.postDelayed(this, 100);
             if ((w >= minWidth) && (w < maxWidth) && (toggle == 1)) {
                 w++;
                 h++;
                 if (w == maxWidth) {
                     toggle = 0;
                 }
             } else {
                 w--;
                 h--;
                 if (w == minWidth) {
                     toggle = 1;
                 }
             }
             View view_instance = (View) findViewById(R.id.surface);
             LayoutParams params = view_instance.getLayoutParams();
             params.width = w;
             params.height = h;
             view_instance.setLayoutParams(params);
         } catch (Exception e) {
             // TODO: handle exception
         } finally {
             //also call the same runnable 
             handler.postDelayed(this, 100);
         }
     }
 };
 handler.postDelayed(runable, 100);

      

thank

+3


source to share





All Articles