Imageview skipped Frames

孤街醉人 提交于 2019-12-19 11:24:30

问题


i've got a Static Page in a Framework. My Navigation Drawer skip frames, when i'm loading the pictures the first time. Now just 3.

Like that: -Title -Image (1000px x 350px, 50kb) -Text

I want to use more Pictures in this Page but doens't think this will look good, because i have skipping Frames on the Nexus 4 and want this App to run also on Low End Devices.

I set the Images in the XML-File. Is there a better way to do this? AsyncTask

Got it myself. Hope i can help anybody with this Problem in the future :)

    private class ImageLoaderTask extends AsyncTask<String, Integer, String> {

    @Override
    protected String doInBackground(String... params) {
//This is updated to load the images before setting them
            final Drawable res_befree = getResources().getDrawable(R.drawable.sc_befreejpg);
            final Drawable res_morepower = getResources().getDrawable(R.drawable.sc_morepower);
            final Drawable res_savemoney = getResources().getDrawable(R.drawable.sc_savemoney);
            final Drawable res_lifequality = getResources().getDrawable(R.drawable.sc_lifequality);

//Update End

        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {

                // This code will always run on the UI thread, therefore is safe to modify UI elements.
                ProgressBar pb_befree = (ProgressBar) getActivity().findViewById(R.id.pb_befree);
                ImageView befree = (ImageView) getActivity().findViewById(R.id.befree);
                befree.setImageResource(R.drawable.sc_befreejpg);
                pb_befree.setVisibility(View.GONE);
                befree.setVisibility(View.VISIBLE);
            }
        });


        return "All Done!";
    }}

Have to put this in my Fragment. Now Images are loading and then set in the UI. UI runs without skipping frames.

来源:https://stackoverflow.com/questions/26565127/imageview-skipped-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!