I am really curious how to limit the calls of these methods onMeasure()
, onLayout()
, onDraw()
. Since I know they are called everytime the View
need to resize if any other View
is being added. Am I thinking right? I want to know how to avoid checking the size and setting the height and width (especially during onMasure()
) if the rest of the Views
has got exactly the same dimensions. In my application View
is in fragment where I have got <ScrollView>
and I <include>
more layouts
there:
<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>
The methods responsible for setting the view are called about 10 times. I want to set the dimensions just once because I @Override
'd them to do some more work there and load the options of the HTML
(those views are WebView
's). I want to load data only once but since the methods in the title are called multiple times I load things many times. It causes some kind of shutter on my screen. Is there any trick to check the dimensions and if they are different then set them again or is there a way to prevent calling these methods?
@EDIT
This is what I'm doing in onMeasure()
method:
@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));
}
The rest HTML (base scripts which are needed) is loaded in onAttachedToWindow
but I have no idea where to put this method: loadDataWithBaseURL
. I tried each of the mentioned method onMeasure, onLayout, onDraw, but that is done 10 times.