这是我向 SO 提出的第一个问题。
我刚刚将 RecyclerView 与 CardView 的 GridManagerLayout 一起使用。现在这一切都与 CustomAdapter 完美配合,但我想在这些 CardView 后面设置一个背景图像,这样它们就不会那么光秃秃的了。
现在我尝试将背景图像设置为使用它的 fragment ,保存 RecyclerView 的 XML 布局 (FrameLayout),然后尝试对 RecyclerView 本身进行同样的操作。
尝试设置一个图像让我很难受,因为这似乎很棘手。
有什么办法可以做到吗?
编辑:
持有 RecyclerView 的布局:
<LinearLayout 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"
android:background="@drawable/background"
tools:context="fragments.SpaceFlightFragment">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
fragment 中创建View的方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_spaceflight, container, false);
RecyclerView recyclerView = (RecyclerView)v.findViewById(R.id.recyclerView);
SpaceFlightAdapter spaceFlightAdapter = new SpaceFlightAdapter(missions);
recyclerView.setAdapter(spaceFlightAdapter);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
return v;
}
现在我尝试将 XML 布局中的背景图像设置为所有标签、LinearLayout、FrameLayout 和 RecyclerView。
我也尝试过在 OnCreateView 方法中将图像动态添加到它们......仍然没有:/。
最佳答案
找到了答案。是一个愚蠢的错误!一切都做对了,但图像有点大,没有创建。所以测试了一个较小的图像来尝试它并且它有效.....应该在询问之前尝试另一个图像。如果这是一个大问题,则期待 OutOfMemory 异常。感谢 david145 和 hars。
关于android - RecyclerView 的 GridLayout View android 上的背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33330119/