我有一个水平gridview,我想要它,所以当你滚动时,一次只会显示一个项目。 一个项目具有屏幕的宽度,因此当您向左滑动时,我希望它能够平滑地滚动到下一个项目。
此外,如果您将一个项目滚动到一半,它应该返回到该项目。
我现在非常困难,谢谢!
public class FrameGridAdapter extends RecyclerView.Adapter<FrameGridAdapter.SimpleViewHolder>{
public static final String BUTTON_UPLOAD = "0x111";
private Context context;
private List<FRData> elements;
public FrameGridAdapter(Context context, ArrayList<FRData> data){
this.context = context;
this.elements = data;
}
public static class SimpleViewHolder extends RecyclerView.ViewHolder {
public final TextView txt_fNo;
public final ImageView img_frame_bm;
public SimpleViewHolder(View view) {
super(view);
txt_fNo = (TextView) view.findViewById(R.id.txt_edit_frame_no);
img_frame_bm = (ImageView) view.findViewById(R.id.img_edit_frame);
}
}
@Override
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view = LayoutInflater.from(this.context).inflate(R.layout.grid_frames_item, parent, false);
return new SimpleViewHolder(view);
}
public void onBindViewHolder(SimpleViewHolder holder, final int position) {
holder.txt_fNo.setText("Frame #" + elements.get(position).frame_no);
holder.img_frame_bm.setImageBitmap(elements.get(position).frame_bm);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return this.elements.size();
}
}
private void DisplayFramesForEdit() {
ArrayList<FRData> frames_list = new ArrayList<FRData>();
for (Bitmap bm: last15shots) {
try
{
FRData frame_temp = new FRData();
frame_temp.frame_bm = bm;
frame_temp.frame_no = last15shots.indexOf(bm);
frames_list.add(frame_temp);
} catch (Exception e)
{
e.printStackTrace();
}
}
FrameGridAdapter fr_adapter;
fr_adapter = new FrameGridAdapter(VideoEditorActivity.this, frames_list);
frames_grid.setAdapter(fr_adapter);
}
这是代码。