我目前正在创建一个应该包含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;
}
}
答案 0 :(得分:0)
我最终无法使用viewPager
弄清楚如何执行此操作,但我发现如何使用horizontalScrollView
来完成此操作。以下是我发布的答案问题的链接。