0

I have a custom LinearLayout and custom TextView, the TextView locates at center. see the xml layout:

<com.example.androidtest.MyLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff0000"
tools:context="com.example.androidtest.MainActivity"
tools:ignore="MergeRootFrame" >

<com.example.androidtest.MyTextView 
    android:id="@+id/test"
    android:text="abc"
    android:layout_gravity="center"
    android:background="#4400ff00"
    android:clickable="true"
    android:layout_width="100px"
    android:layout_height="100px"
    />

</com.example.androidtest.MyLinearLayout>

I override onDraw method in both classes, and add a log ouput like "onDraw in MyTextView called". And I set a onClickListener on the TextView within which i call invalidate().

    tv=(MyTextView)findViewById(R.id.test);
    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                    System.out.println("onClick");
            tv.invalidate();
        }
    });

Example 1: Hardware acceleration: true/false, TextView background color: 0xff00ff00 result: ...->onClick->onDraw in MyTextView..

(Please note that the background color becomes translucent now)

Example 2: Hardware acceleration: false, TextView background color: 0x4400ff00 result: ...->onClick->onDraw in MyLinearLayout->onDraw in MyTextView..

Example 3: Hardware acceleration: true, TextView background color: 0x4400ff00 result: ...->onClick->onDraw in MyTextView..

question 1: the document says that in soft rendering pipeline, ANY view in the view hierachy that intersects with the dirty region will also be redrawn. So according example 1, is it already optimized ?

question 2: in example 3, why the onDraw method in MyLinearLayout isn't called? how could it be? Doesn't it need to draw the parent first and then do alpha blending with TextView?

suitianshi
  • 3,300
  • 1
  • 17
  • 34
  • q2: with hardware acceleration the layout view will be drawn from the displaylist and the onDraw shouldnt be called only the onDraw of the invalidated view shall be recalled. – Karim Tarabishy Jun 21 '14 at 21:53
  • yes, i realized it. There should be a hardware texture backing the parent up. – suitianshi Jun 23 '14 at 03:34

0 Answers0