What is the meaning of [he that would hang his dog gives out first that he is mad]

Those who are planning some action that might attract criticism first seek to justify it in advance.