【发布时间】:2014-12-23 14:17:04
【问题描述】:
我正在使用带有 GridLayoutAdapter 的 RecyclerView。是否可以将项目水平或垂直居中?
我的项目布局:
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/item_photo_image_view"
android:layout_width="@dimen/custom_photo_item_size"
android:layout_height="@dimen/custom_photo_item_size"
android:background="@drawable/custom_image_background"
tools:src="@drawable/gallery_list_cars"/>
</LinearLayout>
其实是这样的:http://oi61.tinypic.com/34pjmtc.jpg
所需的布局应如下所示:http://oi62.tinypic.com/7e2t.jpg
将 RecyclerView 设置为 wrap_content 不起作用,它仍然使用所有可用空间。我想在 RecyclerView 中设置子重力应该是 LayoutManager 的责任。
【问题讨论】:
-
曾经得到过有效的答案吗?
-
没有。我最终硬编码 RecyclerView 宽度并将其水平居中在容器中。
标签: android android-support-library android-recyclerview