0

Необходимо вывести список анимированных гифок. Для работы со списком использую адаптер. Класс приведён ниже:

class GifsListAdapter extends ArrayAdapter{

    private final Activity context;
    ArrayList<GifInfo> gifInfoList;

    public GifsListAdapter(Activity context, ArrayList<GifInfo> gifInfoList) {
        super(context, R.layout.gifs_list, gifInfoList);

        this.context = context;
        this.gifInfoList = gifInfoList;
    }

    @SuppressLint("StaticFieldLeak")
    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View rowView = inflater.inflate(R.layout.gifs_list, null, true);

        TextView txtTitle = (TextView) rowView.findViewById(R.id.gifNameTextView);
        txtTitle.setText(gifInfoList.get(position).getGifName());

        final GifImageView gifImageView = (GifImageView) rowView.findViewById(R.id.giphyImageView);
        new RetrieveByteArray(){
            @Override
            protected void onPostExecute(final byte[] bytes) {
                super.onPostExecute(bytes);
                gifImageView.setBytes(bytes);
                gifImageView.startAnimation();
            }
        }.execute(gifInfoList.get(position).getGifUrl());



        return rowView;
    }

}

При формировании списка гифки появляются, но не анимируются. Может дело в модифкаторе final перед gifImageView ? Класс RetreiveByteArray:

class RetrieveByteArray extends AsyncTask {

    @Override
    protected byte[] doInBackground(String... strings) {
        try{
            URL url = new URL(strings[0]);
            HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
            if(urlConnection.getResponseCode()== 200)
            {
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                int read;
                byte[] data = new byte[10240];
                while((read = in.read(data, 0, data.length)) != -1){
                    buffer.write(data, 0, read);
                }
                buffer.flush();
                return buffer.toByteArray();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

1 ответ 1

0

Start animation это встроенный андроид метод у view, который запускает заданную анимацию перемещений, поворота и т.д. Возможно если у вашего компонента есть такой метод и он должен поиграть гифку, то startAnimation просто не переопределен. Посмотрите в реализацию этого метода в GifImageView. Если ни одна из причин выше не решившие проблемы, то ошибка уже где-то в GifImageView и там уже может быть все что угодно

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.