Android 6.0 以下(正常显示)
Android 6.0(含)以上(有 Bug)
相关代码
/**
* loadView 隐藏时停止播放动画,并设置张小图回收点资源
* @param changedView
* @param visibility
*/
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
// TODO Auto-generated method stub
super.onVisibilityChanged(changedView, visibility);
if (visibility == View.GONE) {
Log.d("loadView", "onVisibilityChanged GONE");
stopAnim();
if(imgv_pic != null){
imgv_pic.setImageResource(R.drawable.ic_user_page_indicator2);
Log.d("loadView", "onVisibilityChanged GONE >> setImage");
}
}
}
布局 xml 代码
<com.a.widget.LoadingView
android:id="@+id/view_no_msg_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone">
</com.a.widget.LoadingView>
Android 6.0 以下执行顺序(含问题分析)>> 先 xml 再 java,针对android:visibility
属性
imgv_pic = null
,不会执行到设置 Image 的语句imgv_pic.setImageResource(R.drawable.ic_user_page_indicator2);
D/loadView: onVisibilityChanged GONE
D/loadView: super init >> inflater.inflate:loadView
D/loadView: init view >> findViewById
D/loadView: init view >> setMode
D/loadView: Visibility >> VISIBLE
Android 6.0(含)以上执行顺序(含问题分析)>> 先 java 再 xml,针对android:visibility
属性
D/loadView: super init >> inflater.inflate:loadView
D/loadView: init view >> findViewById
D/loadView: init view >> setMode
D/loadView: onVisibilityChanged GONE
D/loadView: onVisibilityChanged GONE >> setImage
D/loadView: Visibility >> VISIBLE
问题代码
if(imgv_pic != null){
getRunningAppProcessInfo();
imgv_pic.setImageResource(R.drawable.ic_user_page_indicator2);
Log.d("loadView", "onVisibilityChanged GONE >> setImage");
getRunningAppProcessInfo();
}
日志打印
I/memory: processName=com.a.b.c,pid=19116,uid=10604,memorySize=31992kb
D/loadView: onVisibilityChanged GONE >> setImage
I/memory: processName=com.a.b.c,pid=19116,uid=10604,memorySize=32056kb
在 Android 6.0(含)以上、Android6.0 以下版本中验证修改后的代码,均正常显示。
view.setVisibility(View.VISIBLE)
的方法前,需要再次设置一次图片