Android应用程序ImageView.在设备上不一致



在onResume中,我得到了需要更改可见性的小部件的引用。logcat显示pref中的设置正在正确返回(show_images、show_titles、showdescriptions(。logcat显示if-else正按其应有的方式落入每个if-elses语句中。但在设备上,50%左右的时间,一些卡片在启动时会显示为空白。有些在预处理更改后会显得完全空白,有些时候看起来效果不错。我尝试了一个干净的,干净的构建和CleanUnInstall从设备,但没有运气。这在onResume中。在调用父级onResume并获得首选项之后。

Log.i("INFO", show_images + "" + " "+ show_titles +" " + show_descriptions );
//force the layout to load before changing properties
try{
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
if(!show_images){
Log.i("INFO", "show images false");
image1.setVisibility(View.GONE);
image2.setVisibility(View.GONE);
image3.setVisibility(View.GONE);
image4.setVisibility(View.GONE);
image5.setVisibility(View.GONE);
} else{
Log.i("INFO", "show images true");
image1.setVisibility(View.VISIBLE);
image2.setVisibility(View.VISIBLE);
image3.setVisibility(View.VISIBLE);
image4.setVisibility(View.VISIBLE);
image5.setVisibility(View.VISIBLE);
}
if(!show_titles){
Log.i("INFO", "show titles false");
rTitle1.setVisibility(View.GONE);
rTitle2.setVisibility(View.GONE);
rTitle3.setVisibility(View.GONE);
rTitle4.setVisibility(View.GONE);
rTitle5.setVisibility(View.GONE);
}else{
Log.i("INFO", "show titles true");
rTitle1.setVisibility(View.VISIBLE);
rTitle2.setVisibility(View.VISIBLE);
rTitle3.setVisibility(View.VISIBLE);
rTitle4.setVisibility(View.VISIBLE);
rTitle5.setVisibility(View.VISIBLE);
}
if(!show_descriptions){
Log.i("INFO", "show desc false");
rDescription1.setVisibility(View.GONE);
rDescription2.setVisibility(View.GONE);
rDescription3.setVisibility(View.GONE);
rDescription4.setVisibility(View.GONE);
rDescription5.setVisibility(View.GONE);
}else{
Log.i("INFO", "show desc true");
rDescription1.setVisibility(View.VISIBLE);
rDescription2.setVisibility(View.VISIBLE);
rDescription3.setVisibility(View.VISIBLE);
rDescription4.setVisibility(View.VISIBLE);
rDescription5.setVisibility(View.VISIBLE);
}
}`

不确定原因。。。。但是将布局从constraintLayout转换为linearlayout。然后同样的onResume控制了小部件的可见性。布局问题需要调整,但数据持久性的工作方式与一样

相关内容

  • 没有找到相关文章

最新更新