使用ViewPager逐个显示大量图片。自定义ViewPager使用 PagerContainer by refer this example。在ViewPager中默认有两个图像视图,两个图像视图都可见。但是我想在ViewPager中选择隐藏的一个图像视图。例如,视图分页器当前位置在2中意味着第二个位置的模糊图像将变为不可见。在所有其他位置,模糊图像是可见的。我不知道如何任何人都知道帮助我解决这个问题。
查看寻呼机声明
ema = new Executive_member_adapter(getActivity());
executive_cont = (PagerContainer)findViewById(R.id.executive_memeber_container);
executive_members = executive_cont.getViewPager();
executive_members.setAdapter(ema);
executive_members.setOffscreenPageLimit(ema.getCount());
executive_members.setPageMargin(15);
executive_members.setClipChildren(false);
executive_members.setOnPageChangeListener(ema);
PagerAdapter
public class Executive_member_adapter extends PagerAdapter implements OnPageChangeListener{
LayoutInflater inflater;
Activity activity;
ImageView members_img,blur_img;
int photos[] = {R.drawable.pic1,R.drawable.pic2,R.drawable.pic3,R.drawable.pic4,R.drawable.pic5,R.drawable.pick6};
public Executive_member_adapter(Activity activity) {
// TODO Auto-generated constructor stub
this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return photos.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
// TODO Auto-generated method stub
return view == ((RelativeLayout) object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View)object);
}
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
View itemView;
itemView = inflater.inflate(R.layout.executive_members_pic, container, false);
members_img = (ImageView)itemView.findViewById(R.id.memebers_image);
members_img.setBackgroundResource(photos[position]);
blur_img = (ImageView)itemView.findViewById(R.id.blur_image);
((ViewPager) container).addView(itemView);
return itemView;
}
@Override
public void onPageScrollStateChanged(int position) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int position, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
您要显示图像的数组,您可以动态添加/删除要隐藏或显示的图像。
答案 1 :(得分:0)
你是说这个意思吗? 在所选页面上,ImageView变得不可见。在这种情况下,ViewPager有4页。
@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
blur_img.setVisibility(ImageView.VISIBLE);
break;
case 1:
blur_img.setVisibility(ImageView.GONE);
break;
case 2:
blur_img.setVisibility(ImageView.VISIBLE);
break;
case 3:
blur_img.setVisibility(ImageView.VISIBLE);
break;
}