有没有办法在listView中包含ViewPager从一张图片转换到另一张图片?

时间:2016-07-14 17:10:25

标签: java android listview android-viewpager

我目前正在创建一个应该包含listView textView的应用程序,而在textView下应该包含一个imageView许多图像,但我一次只能看到一个图像。我希望能够在imageView上滑动,以便我可以从一张图片转换到另一张图片,而无需离开活动。是否有任何方法可以在https://developer.android.com/training/animation/screen-slide.html中包含ViewPager,但是在listView或类似的内容中为了完成此操作?如果它有用,我已经包含了我的自定义适配器,目前只支持文本和一个图像。

public class MyAdapter extends BaseAdapter {
    private Context mContext;
    private List<Bean> mList;
    private PopupWindow popUpWindow;
private LayoutInflater inflater;

    public MyAdapter(Context context,List<Bean> list){
        mContext=context;
        mList=list;


}

@Override
public int getCount() {
    return mList.size();
}

@Override
public Object getItem(int position) {
    return mList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    //use convertView recycle
    if(convertView==null){
        holder=new ViewHolder();
        convertView = LayoutInflater.from(mContext).inflate(R.layout.content_orders, parent, false);
        holder.textView= (TextView) convertView.findViewById(R.id.textView2);
        holder.imageView= (ImageView) convertView.findViewById(R.id.imageView2);
        holder.information= (Button) convertView.findViewById(R.id.button5);
        convertView.setTag(holder);
    }else{
        holder = (ViewHolder) convertView.getTag();
    }

    //set text and url
    final View finalConvertView = convertView;
    holder.information.setOnClickListener(new View.OnClickListener() {



        @Override
        public void onClick(View v) {
            inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            ViewGroup container = (ViewGroup) inflater.inflate(R.layout.information_popup, null);
            popUpWindow = new PopupWindow(container, 800,400,true);
            popUpWindow.showAtLocation(finalConvertView.findViewById(R.id.orders), Gravity.CENTER, 0,0);

            container.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    popUpWindow.dismiss();
                    return true;
                }
            });
        }
    });

    holder.textView.setText(mList.get(position).getText());
    Picasso.with(mContext).load(mList.get(position).getUrl()).resize(500,500).into(holder.imageView);

    return convertView;
}

class ViewHolder{
    TextView textView;
    ImageView imageView;
    Button information;
    Button close;

}
}

1 个答案:

答案 0 :(得分:0)

我最终无法使用viewPager弄清楚如何执行此操作,但我发现如何使用horizontalScrollView来完成此操作。以下是我发布的答案问题的链接。

Adding a Horizontal Scroll View to a ListView