Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically change layout height, ClassCastException?

I'm trying to "animate" a WebView to drop down and reveal its contents. I've written a handler to increase the height by 1 each time, however, I'm running into a ClassCastException. The code I'm using is:

WebView.LayoutParams params = new WebView.LayoutParams(wv.getLayoutParams());
params.height = height;
wv.setLayoutParams(params);
height++;
this.sleep(20);

On the line wv.setLayoutParams(params), I get a:

java.lang.ClassCastException: android.widget.AbsoluteLayout$LayoutParams

How do I fix this?

like image 575
Seth Nelson Avatar asked Feb 24 '11 04:02

Seth Nelson


3 Answers

use it-

ViewGroup.LayoutParams vc=webview.getLayoutParams();
        vc.height=700;
        vc.width=450;

        webview.setLayoutParams(vc);

It will work

like image 77
Ravi Avatar answered Nov 04 '22 03:11

Ravi


following is the code of setting size of activity, i hope this will solve your problem. In my case this code works.

WindowManager.LayoutParams params = getWindow().getAttributes();    
       params.height = 200;
       params.width = 220;         

       this.getWindow().setAttributes(params); 
like image 22
user609239 Avatar answered Nov 04 '22 02:11

user609239


The layout paramaters should be of the type of the parent of your view. For instance, if your WebView is inside a LinearLayout, use LinearLayout.LayoutParams.

like image 27
Romain Guy Avatar answered Nov 04 '22 01:11

Romain Guy