我正在使用GridLayoutManager在recyclerview中以水平方向显示一些图像。 但是图像在recyclerview中是不可见的。当我点击空白处时,它在另一个活动中显示图像,但是在recyclerview中它们是不可见的。我尝试了VERTICAL,它们非常好而且可见。
这是我的片段xml:
<RelativeLayout>
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:rotation="180"
android:scaleType="centerCrop"
app:srcCompat="@drawable/page_start" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:visibility="visible"
android:layout_height="match_parent" />
</RelativeLayout>
fragment.java:
RecyclerView rv;
List<Cards> cardsList;
Context context;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = getActivity();
View rootView = inflater.inflate(R.layout.fragment_cards, container, false);
readJson readJson = new readJson(context);
cardsList = readJson.getcardsList();
rv = rootView.findViewById(R.id.rv);
rv.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false));
rv.setAdapter(new CardsListAdapter(empty, context));
答案 0 :(得分:0)
"rv.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false));"
在行下使用
rv.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, true));
或
rv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, true));