2

我正在尝试以一种看起来像是动画/扩展的方式以编程方式更改 webview(用于显示 html)的高度。我的代码工作,但它是滞后的。有时它运行平稳,有时它运行缓慢,通常速度会随着运动而变化。我的代码如下。有没有人有什么好的方法来解决这个问题?

class ViewDropDownASynch extends AsyncTask<String,Void,String>{
    WebView wv;
    int height = 0;
    LinearLayout.LayoutParams params;
    int stop;
    int step;

    public ViewDropDownASynch(WebView v, int a, int o, int e){
        wv = v; 
        params = new LinearLayout.LayoutParams(wv.getLayoutParams());
        height = a;
        stop = o;
        step = e;
        textAnimateExecute = true;
    }
    public String doInBackground(String... para){


        for(int i = height; i != stop+step; i+=step){
            params.height = i;
            SystemClock.sleep(4);
            this.publishProgress();
        }
        return "";
    }

    protected void onPostExecute(String result){
        textAnimateExecute = false;
    }

    protected void onProgressUpdate(Void...values){
        wv.setLayoutParams(params);
    }
4

2 回答 2

2

做布局是非常昂贵的,你将无法避免滞后。要制作这种动画,您应该为视图的快照制作动画。

于 2011-02-25T02:40:58.753 回答
2

我找到了一种更好的替代方法。对于那些想要制作类似动画的人,请参阅我对这个问题的回答:Android:展开/折叠动画

于 2011-02-26T01:04:03.693 回答