Android 跳过了844帧!使用微调器的简单AlertDialog导致主线程中的工作过多

Android 跳过了844帧!使用微调器的简单AlertDialog导致主线程中的工作过多,android,android-dialogfragment,Android,Android Dialogfragment,我使用带有两个微调器的AlertDialog,应用程序本身速度非常快,但当我启动此对话框时,应用程序会在对话框完成时减速,速度会提高 其中一个微调器非常“重”,它包含60个元素,由一个图片和一个文本视图组成。图片(ImageView)很小,但原始图片是512x512 PNG 12,54kB(这是不是太大了?) 一个ArralyList(用于小微调器)直接初始化,小的在应用程序启动时初始化 这是AlertDialog 公共类对话框\u请求扩展AppCompatDialogFragment{ 私有静

我使用带有两个微调器的AlertDialog,应用程序本身速度非常快,但当我启动此对话框时,应用程序会在对话框完成时减速,速度会提高

其中一个微调器非常“重”,它包含60个元素,由一个图片和一个文本视图组成。图片(ImageView)很小,但原始图片是512x512 PNG 12,54kB(这是不是太大了?)

一个ArralyList(用于小微调器)直接初始化,小的在应用程序启动时初始化

这是AlertDialog
公共类对话框\u请求扩展AppCompatDialogFragment{
私有静态最终字符串TAG=“dialog\u cardrexcurequ”;
私有ArrayList printStatesList;
专用微调器sp_对话框打印机;
私人纺纱机sp_请求_国家/地区;
private SendChooseConcountry和PrintState侦听器;
@凌驾
公共void-onAttach(上下文){
super.onAttach(上下文);
试一试{
listener=(dialog\u cardRecruptRequest.sendChooseConcountryandPrintState)上下文;
}catch(ClassCastException e){
抛出新的ClassCastException(context.toString()+
“必须实现SendChooseCountryandPrintState侦听器”);
}
}
@凌驾
创建对话框上的公共对话框(Bundle savedInstanceState){
initarray();
AlertDialog.Builder=新建AlertDialog.Builder(getActivity(),R.style.AlertDialogTheme);
LayoutFlater充气机=getActivity().GetLayoutFlater();
视图=充气机。充气(R.layout.dialog\u请求,空);
最终整数驱动器;
最终int ICcurrentDriverPosition;
Bundle receivingBundle=this.getArguments();
if(receivingBundle!=null){
Driver=receivingBundle.getInt(“驱动程序”);
icCurrentDriverPosition=receivingBundle.getInt(“CurrentCountryPosition”);
}否则{
驱动程序=INT_默认值;
iCurrentDriverPosition=0;
}
builder.setView(视图)
.setTitle(R.string.dialog\u请求\u Title);
setNegativeButton(R.string.Cancle,新的DialogInterface.OnClickListener(){
@凌驾
公共void onClick(DialogInterface,inti){
}
});
setPositiveButton(R.string.ok,新的DialogInterface.OnClickListener(){
@凌驾
公共void onClick(DialogInterface,inti){
obj_Country selectedCountry=(obj_Country)sp_对话框CardReturnRequest_Country.getSelectedItem();
字符串sSelectedCountry=selectedCountry.getsHexCountryCode();
obj_PrintState selectedPrintState=(obj_PrintState)sp_DialogCardRecrumpRequest_Printer.getSelectedItem();
字符串sSelectedPrintRequest=selectedPrintState.getsPrinterRequestHex();
选择国家和打印状态(选择国家、选择打印请求、驱动程序);
}
});
sp_DialogCardDraweRequest_Country=view.findViewById(R.id.sp_DialogCardDraweRequest_Country);
sp_dialogCardDraweRequest_Printer=view.findViewById(R.id.sp_dialogCardDraweRequest_Printer);
适配器\微调器\国家/地区适配器国家/地区=新适配器\微调器\国家/地区(getContext(),objCountryList);
适配器\微调器\打印机适配器打印机=新适配器\微调器\打印机(getContext(),printStatesList);
sp_对话框CARDREQUEST_Country.setAdapter(adapterCountry);
sp_对话框CARDREQUEST_Printer.setAdapter(adapterPrinter);
sp_对话框CARDREQUEST_国家/地区设置选择(iCurrentDriverPosition);
返回builder.create();
}
私有void initarray(){
printStatesList=新的ArrayList();
添加(新的obj_PrintState(PRINTREQUEST_NONE,getText(R.string.dialog_cardRequiremeRequest_NONE).toString());
printStatesList.add(新的obj_PrintState(PRINTREQUEST_UTC,getText(R.string.dialog_cardReturnRequest_PRINTREQUEST_UTC.toString());
添加(新的obj_PrintState(PRINTREQUEST_LOCAL,getText(R.string.dialog_cardRecruptRequest_PRINTREQUEST_LOCAL).toString());
}
公共接口SendChooseCountry和PrintState{
void选择CountryandPrintState(字符串sSelectedCountry,字符串sSelectedPrintRequest,int-Driver);
}
}
这是来自mainActivity的电话
helperThread=newhandlerThread(“helperThread”);
helperThread.start();
Handler helperHandler=新处理程序(helperThread.getLooper());
helperHandler.post(新的Runnable(){
@凌驾
公开募捐{
dialog_CardDrumeRequest dialog_CardDrumeRequest=新建dialog_CardDrumeRequest();
Bundle information=新Bundle();
信息。输入(“驾驶员”,iDriver);
信息。输入(“当前国家位置”,最终定位);
对话框\u请求。设置参数(信息);
显示(getSupportFragmentManager(),“CardDruchRequest”);
}
});
如您所见,我已经尝试在不同的线程上发布这项“艰巨的工作”,但我认为
AlertDialog
总是在UI线程中运行,我不知道

我还尝试使用:

runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
}
});

。。。512x512 PNG 12,54kB(这个太大了吗?
。。。是的

考虑到解压缩后的原始位图是x*y*4字节(R、G、B和A分量,每个分量权重为1个完整字节)。
因此,您的每个图像在内存中的权重为1MB

顺便说一下,不需要使用ImageView:只需在TextView中将图像设置为可绘制的复合图像,并挤出一些性能

这里有一个有趣的链接:

您认为0.1MB是否足够小?您应该试着感觉一下它是否足够大