在android中将多个图像添加到水平滚动视图 [英] Adding multiple images to horizontal scroll view in android

查看:145
本文介绍了在android中将多个图像添加到水平滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,我想在水平滚动视图中添加多个图像并且想要点击两个(左和右)srcolling按钮滚动这些图像,但我无法做到这一点,因为我是Android开发新手。所以任何人都可以提供我的解决方案如何做到这一点?在此先感谢....

I am building an application in which I want to add multiple images in a horizontal scrollview and want to scroll these imageson click of two (left and right) srcolling buttons, but I am not able to do that as I am new to android development.So can anybody provide my with the solution how to do it ? Thanks in advance....

推荐答案

将此代码放入xml

<HorizontalScrollView
        android:id="@+id/xml_full_img_hor_below_view"
        android:layout_width="match_parent"
        android:layout_height="@dimen/full_img_below_relative_height"
        android:layout_alignParentBottom="true"
        android:layout_gravity="center"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/xml_full_img_linear_below_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>

///////////////////// ////////////////
java code

///////////////////////////////////// java code

model_ProductMaster.listProductImages.size()是图像列表:

private void setProductImageInView() {

        LayoutInflater layoutInflater = (LayoutInflater) viewFullImage
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        linear_below_img_view.removeAllViews();
        // Set the image height,widt,scaling and margin of the imageview
        for (int i = 0; i < model_ProductMaster.listProductImages.size(); i++) {
            convertView = layoutInflater.inflate(
                    R.layout.xml_row_full_image_view, null, false);
            final ImageView img = (ImageView) convertView
                    .findViewById(R.id.xml_full_img_below_middleimg);
            img.setMinimumWidth((int) viewFullImage.getResources()
                    .getDimension(R.dimen.full_img_below_img_width_height));
            img.setMaxWidth((int) viewFullImage.getResources().getDimension(
                    R.dimen.full_img_below_img_width_height));
            img.setMinimumHeight((int) viewFullImage.getResources()
                    .getDimension(R.dimen.full_img_below_img_width_height));
            img.setMaxHeight((int) viewFullImage.getResources().getDimension(
                    R.dimen.full_img_below_img_width_height));
            img.setScaleType(ScaleType.CENTER_INSIDE);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins(10, 0, 0, 0);
            layoutParams.gravity = Gravity.CENTER;
            convertView.setLayoutParams(layoutParams);
            img.setScaleType(ScaleType.FIT_XY);
            imageLoader.displayImage(
                    model_ProductMaster.listProductImages.get(i).ImageUrl, img,
                    options, animateFirstListener);
            linear_below_img_view.addView(convertView);
            convertView.setId(i);
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int i = 0; i < linear_below_img_view.getChildCount(); i++) {
                        View view = linear_below_img_view.getChildAt(i);
                        if (view == v) {
                            view.setBackgroundResource(R.drawable.xml_popup_border_with_bg);
                        } else {
                            view.setBackgroundResource(R.drawable.common_bg_with_dark_border);
                        }
                    }

                    loadImageonCenter(model_ProductMaster.listProductImages
                            .get(v.getId()).ImageUrl);
                    System.gc();
                }
            });

        }
        linear_below_img_view.getChildAt(0).setBackgroundResource(
                R.drawable.xml_popup_border_with_bg);
        // Image Starting load

        System.gc();
    }

这篇关于在android中将多个图像添加到水平滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆