2017-03-01 92 views
0
if (image.getDrawable().getConstantState().equals(getResources().getDrawable(0).getConstantState())){ 
      image.setVisibility(View.GONE); 
     }else{ 
      image.setVisibility(View.VISIBLE); 
     } 

也就是说,如果图像没有任何可绘制,图像将会消失,否则可见。但是这个代码不工作检查是否ImageView的有绘制

回答

0
if (image.getDrawable().getConstantState().equals 
      (getResources().getDrawable(R.drawable.your_drawable).getConstantState()){//set here your drawable name(your_drawable) 
      image.setVisibility(View.VISIBLE); 
     }else{ 
      image.setVisibility(View.GONE); 
     } 
0
其实

,还有另一种方式来比较:

if(imageView.getDrawable().getConstantState().equals 
      (getResources().getDrawable(/*Your drawable*/).getConstantState())) 
imageView.setVisibility(View.VISIBLE); 
     else 
      imageView.setVisibility(View.GONE); 
0
if(imageview.getDrawable()==null) 
    { 
     //if Image View is Null 
    } 

检查source

0

尝试以下可能是你的作品(这对我的工作)

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { 
    if (image.getDrawable().getConstantState().equals(image.getContext().getDrawable(R.drawable.shadow_round_white).getConstantState())){ 

     image.setVisibility(View.GONE); 
    } 
    else{ 
     image.setVisibility(View.VISIBLE); 
    } 

} 
else { 
    if (image.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.shadow_round_white).getConstantState())){ 
     image.setVisibility(View.GONE); 
    } 

    else{ 
     image.setVisibility(View.VISIBLE); 
    } 
}