View.getBackground()返回null
? ? ? ? ? ? ? ? if(mAnimView != null){
? ? ? ? ? ? ? ? ? ? mAnimView.setBackgroundResource(R.drawable.adj);
? ? ? ? ? ? ? ? ? ? mAnimView = null;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? mAnimView = (ImageView) view.findViewById(R.id.view_anim);
? ? ? ? ? ? ? ? mAnimView.setBackgroundResource(R.drawable.play_ainim);
? ? ? ? ? ? ? ? mAnimView.post(new Runnable() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void run() {
? ? ? ? ? ? ? ? ? ? ? ? AnimationDrawable anim = (AnimationDrawable)(mAnimView.getBackground());//這里一直為null
? ? ? ? ? ? ? ? ? ? ? ? anim.start();
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
已經嘗試了將view改為imageview然后通過getDrawable獲取,仍然為空,通過view.post也不行。求救!
2017-06-23
如果你的xml布局文件中的那個控件設置了android:background="..." ,這里就可以用 View.getBackground(); 如果設置的是 android:src="...." ,就用View.getDrawable();
2015-05-06
已解決,xml文件的問題,studio略坑