在recyclerView中,似乎一张cardView占据了整个列表视图[关闭]

问题描述 投票:-2回答:1
我遇到如下问题。

我有3个cardView,但最初只能看到其中一个。像这样。

enter image description here

如果我向下滚动一点,我可以看到另一个。

enter image description here

多一点,

enter image description here

最后,

enter image description here

似乎有一个像这样的小盒子。

enter image description here

我希望以适当的边距列出cardView。在愚蠢的想法中,我在RecyclerView中犯了错误]

这是我的fragment_item_list_view

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment_item_list" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context="com.example.androidaudiorecorder.ItemFragment"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" tools:listitem="@layout/fragment_item"/>

这是我来自RecyclerViewAdapter的课程

public RecordingsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater. from(parent.getContext()). inflate(R.layout.fragment_item, parent, false); mContext = parent.getContext(); return new RecordingsViewHolder(itemView); } public static class RecordingsViewHolder extends RecyclerView.ViewHolder { protected TextView vName; protected TextView vLength; protected TextView vDateAdded; protected View cardView; public RecordingsViewHolder(View v) { super(v); vName = (TextView) v.findViewById(R.id.file_name_text); vLength = (TextView) v.findViewById(R.id.file_length_text); vDateAdded = (TextView) v.findViewById(R.id.file_date_added_text); cardView = v.findViewById(R.id.fragment_item); } }

这是我来自ItemFragment的课程

public class ItemFragment extends Fragment { private ItemRecyclerViewAdapter mItemRecyclerViewAdapter; // TODO: Customize parameter argument names private static final String ARG_COLUMN_COUNT = "column-count"; // TODO: Customize parameters private int mColumnCount = 1; private OnListFragmentInteractionListener mListener; /** * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */ public ItemFragment() { } // TODO: Customize parameter initialization @SuppressWarnings("unused") public static ItemFragment newInstance(int columnCount) { ItemFragment fragment = new ItemFragment(); Bundle args = new Bundle(); args.putInt(ARG_COLUMN_COUNT, columnCount); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT); observer.startWatching(); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_item_list, container, false); // Set the adapter RecyclerView mRecyclerView = (RecyclerView) v.findViewById(R.id.recyclerView); mRecyclerView.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); llm.setOrientation(LinearLayoutManager.VERTICAL); //newest to oldest order llm.setReverseLayout(true); llm.setStackFromEnd(true); mRecyclerView.setLayoutManager(llm); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mItemRecyclerViewAdapter = new ItemRecyclerViewAdapter(getActivity(), llm); mRecyclerView.setAdapter(mItemRecyclerViewAdapter); return v; } @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnListFragmentInteractionListener) { mListener = (OnListFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() + " must implement OnListFragmentInteractionListener"); } } @Override public void onDetach() { super.onDetach(); mListener = null; }

ps.s。我已经尝试将layout_height更改为“ match parent”,但它只影响片段的大小。]

感谢您阅读!如果您能帮我,我将非常高兴!

编辑:这是我的fragment_item.xml代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/fragment_item" android:layout_width="match_parent" android:layout_height="75dp" android:layout_gravity="center" android:layout_margin="5dp" android:foreground="?android:attr/selectableItemBackground" android:transitionName="open_mediaplayer" card_view:cardCornerRadius="4dp" card_view:cardElevation="3dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_android_black_24dp" android:layout_gravity="center_vertical" android:layout_marginLeft="7dp" android:layout_marginRight="7dp"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center_vertical"> <TextView android:id="@+id/file_name_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="file_name" android:textSize="15sp" android:textStyle="bold"/> <TextView android:id="@+id/file_length_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="00:00" android:textSize="12sp" android:fontFamily="sans-serif-condensed" android:layout_marginTop="7dp"/> <TextView android:id="@+id/file_date_added_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="mmm dd yyyy - hh:mm a" android:textSize="12sp" /> </LinearLayout> </LinearLayout> </androidx.cardview.widget.CardView> </LinearLayout>

我遇到如下问题。我有3个cardView,但最初只能看到其中一个。像这样。如果在此处向下滚动,则可以看到另一个。输入图片...
android android-recyclerview android-cardview
1个回答
3
投票
将项目的宽度更改为“ match_parent”,将高度更改为“ wrap_content”
© www.soinside.com 2019 - 2024. All rights reserved.