图片在 Recycler View 中无法正确显示

Images not Showing Properly in Recycler View

我的 Recycler View 出现问题,图片显示不正确,

这里是链接,您可以在其中看到我正在做的事情

  1. https://ibb.co/jXgXU9
  2. https://ibb.co/ceTCU9
  3. https://ibb.co/jkFsU9
  4. https://ibb.co/jkFsU9
  5. https://ibb.co/ffte99

当将 Recycler 视图 width 更改为 match-parent 并将 height 更改为 wrap_content 时,它可以工作但是向下滚动然后出现备份它搞砸了,一次只显示一张图片

  1. 这是 customlayout.xml

    的代码
      <LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
    
    
       <ImageView
           android:id="@+id/listicon"
           android:layout_width="match_parent"
           android:layout_height="220dp" />
    
       </LinearLayout>
    
    1. 这是我的fragment_home.xml

      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".HomeFragment">
      <android.support.v7.widget.RecyclerView
         android:id="@+id/drawerList"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:layout_alignParentLeft="true">
      
         </android.support.v7.widget.RecyclerView>
      
          </FrameLayout>
      

3.Here 是 HomeFragment.java

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v7.widget.LinearLayoutManager;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    public class HomeFragment extends Fragment  {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private CustomAdapter adapter;
    int[] IMAGES = {R.drawable.abs,R.drawable.arms,R.drawable.back,R.drawable.chest,R.drawable.full,R.drawable.legs};
    private RecyclerView recyclerView;


    ArrayList<HashMap<String, String>> data;


    private String mParam1;
    private String mParam2;


    public HomeFragment() {

      }
    public static HomeFragment newInstance(String param1, String param2) {                   
    HomeFragment fragment = new HomeFragment();
    Bundle args = new Bundle();
    args.putString(ARG_PARAM1, param1);
    args.putString(ARG_PARAM2, param2);
    fragment.setArguments(args);
    return fragment;
        }
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mParam1 = getArguments().getString(ARG_PARAM1);
        mParam2 = getArguments().getString(ARG_PARAM2);
    }
        }
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View layout = inflater.inflate(R.layout.fragment_home, container, false);
     recyclerView =(RecyclerView) layout.findViewById(R.id.drawerList);
     adapter = new CustomAdapter(getActivity(), getData());
     recyclerView.setAdapter(adapter);
     recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return layout;
      }

    public static List<Information> getData(){
    List<Information> data = new ArrayList<>();
    int [] icons = {R.drawable.abs,R.drawable.arms,R.drawable.back,R.drawable.chest,R.drawable.full,R.drawable.legs};
    String[] titles={"Abs","Arms","Back","Chest","full","legs"};
    for (int i=0; i<icons.length && i<titles.length;i++){

        Information current = new Information();
        current.images=icons[i];
        current.title=titles[i];
        data.add(current);
    }
    return data;

    }





    }

当您使用 RecyclerView 并将为列表制作一个 xml 文件时,在这种情况下您必须使用 wrap_content 作为高度,否则它会在您滚动时占用设备的高度。

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">


<ImageView
   android:id="@+id/listicon"
   android:layout_width="match_parent"
   android:layout_height="220dp />

    </LinearLayout>

在 java 中执行此操作:

recycler = (RecyclerView) layout.findViewById(R.id.recycler);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recycler.setLayoutManager(layoutManager);
adapter = new CustomAdapter(getActivity(), getData());
recyclerView.setAdapter(adapter);

在 fragment_home.xml 中将其添加到我的回收站视图中就成功了

    android:clipToPadding="false"
    android:scrollbars="vertical"