I have a situation where I want to debug calls to TextView.onDraw()
so I subclassed it like this:
public class MyTextView extends AppCompatTextView {
View parent;
public MyTextView(Context context) {
super(context);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void storeParent(View parent) {
this.parent = parent;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
and put it up inside a hierarchy like this:(see MyTextView
)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.scrollviewtest1.MainActivity">
<LinearLayout
android:id="@+id/scroll_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.example.scrollviewtest1.MyTextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/large_text" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
</ScrollView>
Lastly, I put a very large piece of text for this TextView
so that it becomes scrollable.
Now, if I put a breakpoint inside the onDraw()
method, I only get one call to it. As per my understanding, I should be getting call to it as I scroll up and down. Why is this happening?
Side note: I have already tried setting setWillNotDraw(false)
with no change in the outcome.
Credit goes to @pskink for suggesting turning off H/W acceleration for this; it worked. Here is what docs say about this:
VS