Android模拟器中RecyclerView仅显示首张图片问题求助
Hey there! As a new Android developer, it’s totally normal to hit snags like this—let’s walk through the most common fixes first before blaming the emulator (since 9 times out of 10, it’s not the emulator’s fault!).
First, Check Your Adapter’s getItemCount() Method
This is the #1 culprit for this issue. If your adapter is only returning 1 instead of the size of your data list, RecyclerView will only ever show the first item. Open your Adapter class and double-check this method:
@Override public int getItemCount() { // Make sure this returns your data list's size, not a hardcoded 1! return mImageList.size(); // ✅ Correct // return 1; ❌ Wrong—this will only show the first item }
Verify Your Item Layout’s Height
If your item’s root view uses match_parent for its height, each item will take up the entire screen. You’ll have to scroll to see the next one, but it might look like only the first item is showing. Fix this by setting the item’s root layout height to wrap_content or a fixed size (like 200dp):
<!-- Example correct item layout --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" <!-- Avoid match_parent here --> android:padding="16dp"> <ImageView android:id="@+id/item_image" android:layout_width="match_parent" android:layout_height="180dp" android:scaleType="centerCrop"/> </LinearLayout>
Ensure RecyclerView Has Proper Layout Constraints
If your RecyclerView isn’t sized correctly in its parent layout, it might only have enough space to show one item. For example, in a ConstraintLayout:
- Make sure the RecyclerView is constrained to both the top and bottom of its parent (so it takes up all available space)
- Avoid setting a fixed height that’s too small
Here’s a correct RecyclerView setup:
<androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/>
Confirm Your Data Source Has Multiple Items
It sounds obvious, but double-check that your list of images actually contains more than one entry! For example, in your Activity/Fragment:
// Make sure you're adding multiple images to your list List<Integer> imageResources = new ArrayList<>(); imageResources.add(R.mipmap.image_1); imageResources.add(R.mipmap.image_2); imageResources.add(R.mipmap.image_3); // Don't forget this line! MyImageAdapter adapter = new MyImageAdapter(imageResources); recyclerView.setAdapter(adapter);
If All Else Fails, Test the Emulator (or a Real Device)
If you’ve checked all the above and still see only the first item, let’s rule out the emulator:
- Try a different emulator: Create a new AVD (e.g., Pixel 5 with API 33) and run your app there. Sometimes old or misconfigured emulators can act weird.
- Test on a real device: If you have access to an Android phone, install your app there. If it works on the device but not the emulator, the issue is likely with the emulator—try updating Android Studio, restarting the emulator, or toggling hardware acceleration in the emulator settings.
内容的提问来源于stack exchange,提问作者AshS

