回收视图 wrap_content
RecyclerView wrap_content
当 RecyclerView 的 layout_width 为 wrap_content 时,我试图将其居中,但没有成功
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_schemes"
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
当给 RecyclerView 任何确定的 layout_width 比如说 200dp 时,它就会居中,否则它只是左对齐。
当 layout_width 为 wrap_content 时如何使 RecyclerView center_horizontal ?
与LayoutManager如何计算尺寸有关。 Here 你有与人们使用的一些解决方法相关的错误。
注意:随着支持库的 23.2 版现在支持包装内容,所以看起来他们修复了它。您可以查看更新日志 here
您是否尝试过使用 RelativeLayout
而不是线性布局,然后制作 Recyclerview layout_centerHorizontal="true"
根据您的问题,更新于 (2016 年 3 月)
我建议您更新到 Android Support Library 23.2.1 以在 RecycleView 中支持 WRAP_CONTENT。
在 RecyclerView layout_width 到 wrap_content 在 23.2.1 之前不支持。
解决了一些问题,例如 修复了与各种测量规范方法相关的错误
勾选http://developer.android.com/tools/support-library/features.html#v7-recyclerview
当 RecyclerView 的 layout_width 为 wrap_content 时,我试图将其居中,但没有成功
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_schemes"
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
当给 RecyclerView 任何确定的 layout_width 比如说 200dp 时,它就会居中,否则它只是左对齐。
当 layout_width 为 wrap_content 时如何使 RecyclerView center_horizontal ?
与LayoutManager如何计算尺寸有关。 Here 你有与人们使用的一些解决方法相关的错误。
注意:随着支持库的 23.2 版现在支持包装内容,所以看起来他们修复了它。您可以查看更新日志 here
您是否尝试过使用 RelativeLayout
而不是线性布局,然后制作 Recyclerview layout_centerHorizontal="true"
根据您的问题,更新于 (2016 年 3 月)
我建议您更新到 Android Support Library 23.2.1 以在 RecycleView 中支持 WRAP_CONTENT。
在 RecyclerView layout_width 到 wrap_content 在 23.2.1 之前不支持。
解决了一些问题,例如 修复了与各种测量规范方法相关的错误
勾选http://developer.android.com/tools/support-library/features.html#v7-recyclerview