如何显示带有进度条和图像的加载图像也想在我的GridView Andriod Studio中计数

时间:2018-08-07 19:17:41

标签: android android-layout android-studio gridview

我创建了一个像gallery这样的android应用程序,其中包含一些使用gridview片段的图像。

我的应用程序功能正常,并且图像显示在片段gridview中,并且当我单击项目时我的第二个活动也打开了,但是当我的图像未加载或加载完成需要时间时,我想显示带有进度条的加载图像。 / p>

我也想在gridview中显示图像计数。

但是我想在加载图像上显示进度条:WANT LINK THIS SCREENSHOT

我的gridview看起来像这样:My gridview looks like this

已找到 这是我的应用程序片段代码:

    public class CallFragment extends Fragment {

GridView grid;
        String[] plan = {
                "Student Bundle",
                "SMS Plus Bundle",
                "Instagram",
                "Facebook",
                "Flickr"

        } ;
        String[] web = {
                "*3000",
                "*106*1",
                "Instagram",
                "Facebook",
                "Flickr"

        } ;
        int[] imageId = {
                R.drawable.calla,
                R.drawable.smsb,
                R.drawable.person7,
                R.drawable.person7,
                R.drawable.person7

        };
        int[] fullimg = {
                R.drawable.callaa,
                R.drawable.smsbb,
                R.drawable.person7,
                R.drawable.person7,
                R.drawable.person7

        };

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            setHasOptionsMenu(true);

            View view = inflater.inflate(R.layout.fragment_call,container,false);

            CustomGrid adapter = new CustomGrid(getActivity(), plan, web, imageId, fullimg);

            grid=(GridView) view.findViewById(R.id.grid);
            grid.setAdapter(adapter);
            grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                    String value=(String)grid.getItemAtPosition(i);
                    Intent intent=new Intent(getActivity(),Book.class);
                    intent.putExtra("web", web[i]);
                    intent.putExtra("plan", plan[i]);
                    intent.putExtra("imageId", imageId[i]);
                    intent.putExtra("fullimg", fullimg[i]);
                    startActivity(intent);

                }
            });

            return view;
        }

这是我的应用程序CustomAdapter代码:

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> {

    ArrayList<String> personNames;
    ArrayList<String> personCode;
    ArrayList<Integer> personImages;
    ArrayList<Integer> personImages1;
    Context context;

    public CustomAdapter(Context context, ArrayList<String> personNames, ArrayList<String> personCode, ArrayList<Integer> personImages, ArrayList<Integer> personImages1) {
        this.context = context;
        this.personCode = personCode;
        this.personNames = personNames;
        this.personImages = personImages;
        this.personImages1 = personImages1;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // infalte the item Layout
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.rowlayout, parent, false);
        // set the view's size, margins, paddings and layout parameters
        MyViewHolder vh = new MyViewHolder(v); // pass the view to View Holder
        return vh;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        // set the data in items
        //holder.name.setText(personNames.get(position));
        holder.image.setImageResource(personImages.get(position));
        //holder.image.setImageResource(personImages1.get(position));
        // implement setOnClickListener event on item view.
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // open another activity on item click
                Intent intent = new Intent(context, SecondActivity.class);
                //intent.putExtra("image", personImages.get(position)); // put image data in Intent
                intent.putExtra("name", personNames.get(position)); // put image data in Intent
                intent.putExtra("code", personCode.get(position)); // put image data in Intent
                intent.putExtra("image", personImages1.get(position)); // put image data in Intent
                context.startActivity(intent); // start Intent
            }
        });

    }


    @Override
    public int getItemCount() {
        return personNames.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        // init the item view's
        TextView name;
        TextView code;
        ImageView image;

        public MyViewHolder(View itemView) {
            super(itemView);

            // get the reference of item view's
            name = (TextView) itemView.findViewById(R.id.name);
            code = (TextView) itemView.findViewById(R.id.code);
            image = (ImageView) itemView.findViewById(R.id.image);

        }
    }
}

另外,如果更容易使用默认图像代替加载图像而不是进度条也可以。

请提供给我解决方案以实施此操作。 我希望您能得到我想要的要点,谢谢您的帮助。

0 个答案:

没有答案