質問

I have a custom ViewGroup that overrides draw() to draw some stuff over its children. It calls setWillNotDraw(false) on the constructor appropriately, and under normal conditions, works as intended.

My problems start when, in the layout XML, on such view I assign a background drawable ("splash screen") and later on in the application I remove this background (setBackgroundDrawable(null)). This happens only once, while application is initializing.

 <com.regaliz.gui.layouts.FunqRootLayout xmlns:android="..."
    .
android:background="@drawable/a_filmnew_cover_play_splash">

From that point, onDraw / draw is never called again whenever I invalidate the ViewGroup.

I've checked the View.java's setBackgroundDrawable source code and saw a lot of logic to manipulate the View Flags to add or remove WillNotDraw-related internal flags (but all the methods are private). I suspect this is what's happening: The call to setBackgroundDrawable(null) sets the willNotDraw flag), however I am not able to enable it again.

Subsequent calls to

 setWillNotDraw(false)

are ignored.

To make things funnier, if I don't assign any background in the XML, the setBackgroundDrawable(null) call doesn't seem to touch the flags, so I don't have this problem.

What can be happening?

This is the splash drawable:

 <?xml version="1.0" encoding="utf-8"?>
 <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
     android:gravity="center"
     android:src="@drawable/a_filmnew_cover_play" />
役に立ちましたか?

解決

try overriding dispatchDraw(Canvas) method

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top