全屏图像滑块

时间:2018-04-06 13:32:57

标签: java android

如何使用viewpager图像

在自定义alertdialog中实现滑块

此滑块有效: ImageSlider

在图片上点击: ImageClick

我的要求是在图像上滑动全屏图像。

MainActivity显示带有viewpager图像的自定义alertdialog:

 // showing custom alertdialog with viewpager images
private void showImages() {

    final Dialog dialog = new Dialog(Post_detailActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_post_image_detail);
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.show();

    vp_dialoge_image = (ViewPager) dialog.findViewById(R.id.vp_dialog_img);
    ImageView iv_dialoge_cancle = (ImageView) dialog.findViewById(R.id.iv_dialog_cancle);
    ImageView iv_dialoge_left = (ImageView) dialog.findViewById(R.id.iv_dialog_left);
    ImageView iv_dialoge_right = (ImageView) dialog.findViewById(R.id.iv_dialog_right);

    vp_dialoge_image.setAdapter(image_pager_adapter);

    vp_dialoge_image.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            current_position_dialog = position;
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    iv_dialoge_cancle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    iv_dialoge_left.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (current_position_dialog > 0) {

                current_position_dialog--;

                vp_dialoge_image.setCurrentItem(current_position_dialog);

            }
        }
    });

    iv_dialoge_right.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (current_position_dialog < total_image) {
                current_position_dialog++;
                vp_dialoge_image.setCurrentItem(current_position_dialog);

            }
        }
    });

}

ImagePagerAdapter显示带有viewpager图像的自定义alertdialog

  public Object instantiateItem(ViewGroup container, final int position) {

    View itemView = layoutInflater.inflate(R.layout.row_image_pager, container, false);

    final Post_image_model mList = modelList.get(position);

    ImageView imageView = (ImageView) itemView.findViewById(R.id.iv_post_image);

    Picasso.with(context)
            .load(BaseURL.IMG_POST_URL + mList.getImage_path())
            .placeholder(R.drawable.ic_loading_02)
            .into(imageView);

    container.addView(itemView);

    //listening to image click
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // check if zoom equel true then show image dialog
            if (is_zoom) {
                showImages(mList.getImage_path());
            }
        }
    });

    return itemView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((LinearLayout) object);
}

// showing custom alertdialog with viewpager images
private void showImages(String imagepath) {

    final Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_image_detail_zoom);
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    dialog.show();



    Button iv_dialoge_cancle = (Button) dialog.findViewById(R.id.iv_dialog_cancle);

    PhotoView iv_dialoge_img = (PhotoView) dialog.findViewById(R.id.iv_dialog_img);



    Picasso.with(context)
            .load(BaseURL.IMG_POST_URL + imagepath)
            .placeholder(R.drawable.ic_loading_02)
            .skipMemoryCache()
            .fit()
            .centerInside()
            .into(iv_dialoge_img);


    iv_dialoge_cancle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

}

有人可以帮忙吗?

0 个答案:

没有答案