我剛完成我的RecyclerView
爲我的Android Application
,但是當測試它時,我發現了一個奇怪的錯誤,我不明白。當活動啓動時,Recycler
視圖中的項目在正確的距離上位於RecyclerView
的位置。但是,一旦我開始滾動,它們將彼此分開,直到一次只能看到一個項目,並且在看到下一個項目之前必須將distance almost equivalent
滾動到屏幕的那個位置。RecyclerView滾動時項目之間的空間擴大
這裏是錯誤的樣子:
上的活動午餐
滾動滾動recycleview
後之前如果您有任何想法可能造成這種情況,任何幫助將不勝感激。
下面是該活動的RecyclerView代碼:
private ArrayList<String> imagesUrlListThumb, imagesUrlListFull = new ArrayList<String>();
private RecyclerAdapter recyclerAdapter;
private String urlRecyclerThumb = "";
private RecyclerView recyclerView;
private ImageView imgCurRecyclerView;
imagesUrlListThumb = produit.getImgUrlThumbMul();
recyclerAdapter = new RecyclerAdapter(getApplicationContext(), imagesUrlListThumb);
recyclerView = (RecyclerView) findViewById(R.id.content_product_detail_recycer_view);
RecyclerView.LayoutManager recyclerLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(recyclerLayoutManager);
recyclerView.setAdapter(recyclerAdapter);
urlRecyclerThumb = imagesUrlListThumb.get(0);
RecyclerItemClickSupport.addTo(recyclerView).setOnItemClickListener(new RecyclerItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView rv, int pos, View view) {
urlRecyclerThumb = imagesUrlListThumb.get(pos);
Picasso.with(getApplicationContext()).load(urlRecyclerThumb).fit().into(imgCurRecyclerView);
}
});
回收站適配器:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder>{
private List<String> urlThumbImg;
private Context context;
public RecyclerAdapter(Context ctx, List<String> urls){
this.urlThumbImg = urls;
this.context = ctx;
}
@Override
public RecyclerAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_slideshow, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(RecyclerAdapter.MyViewHolder holder, int position){
String current = urlThumbImg.get(position);
Picasso.with(context).load(current).fit().into(holder.myImgView);
}
@Override
public int getItemCount(){
return urlThumbImg.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public ImageView myImgView;
public MyViewHolder(View view){
super(view);
myImgView = (ImageView) view.findViewById(R.id.imageView_slide);
}
}
}
這是關於我的XML佈局回收站視圖:
<!-- RECYCLER VIEW -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:orientation="vertical">
<ImageView
android:id="@+id/content_product_detail_recycer_view_cur_image"
android:layout_width="150dp"
android:layout_height="130dp"
android:layout_gravity="center"
android:background="@android:color/black" />
<android.support.v7.widget.RecyclerView
android:id="@+id/content_product_detail_recycer_view"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:background="@android:color/darker_gray">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
佈局項目回收站內:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView_slide"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="5dp"
android:background="@android:color/darker_gray" />
你recyclerView代碼? –
爲recyclerview內的商品和recyclerview的代碼提供佈局 – Kushan
@AhmadAlsanie我已將代碼添加到我的問題 –