0

我真的很好奇如何限制这些方法的onMeasure()调用onLayout(),,,onDraw()。因为我知道每次View需要调整大小时都会调用它们(如果View添加了其他任何东西)。我想对了吗?onMasure()如果其余部分的Views尺寸完全相同,我想知道如何避免检查尺寸并设置高度和宽度(尤其是在 期间)。在我的应用程序中,我View已经得到了片段,而且还有更多:<ScrollView><include>layouts

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
>
    <ScrollView android:layout_width="match_parent" android:layout_height="match_parent">
        <LinearLayout android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:orientation="vertical"
        >
            <include layout="@layout/firts"/>
            <include layout="@layout/second"/>
            <include layout="@layout/third"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

负责设置视图的方法被调用了大约 10 次。我想只设置一次尺寸,因为我想让@Override他们在那里做更多的工作并加载HTML(那些视图是WebView)的选项。我只想加载一次数据,但由于标题中的方法被多次调用,所以我加载了很多次。它会在我的屏幕上引起某种快门。是否有任何技巧来检查尺寸,如果它们不同,然后再次设置它们,或者有没有办法阻止调用这些方法?

@EDIT 这就是我在onMeasure()方法中所做的:

@Override
    protected void onMeasure (int widthMeasureSpec,
                    int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        System.out.println("Measure size...");
        float density = getResources().getDisplayMetrics().density;
        float height = getResources().getDisplayMetrics().heightPixels;
        setMinimumWidth(Math.round(getWidth()/density));
        setMinimumHeight(Math.round(height/density*2/5));
        this.HTML.prepareViewWidth(Math.round(getWidth()/density), Math.round(height/density*2/5));
    }

其余的 HTML(需要的基本脚本)已加载,onAttachedToWindow但我不知道在哪里放置此方法:loadDataWithBaseURL. 我尝试了上面提到的每个方法 onMeasure、onLayout、onDraw,但都做了 10 次。

4

0 回答 0