【问题标题】:RecyclerView wrap_contentRecyclerView wrap_content
【发布时间】:2015-05-06 05:22:04
【问题描述】:

当 RecyclerView 的 layout_widthwrap_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 被指定为 200dp 的任何明确 layout_width 时,它会居中,否则它只会向左对齐。

当RecyclerView的layout_width为wrap_content时,如何使RecyclerView center_horizo​​ntal?

【问题讨论】:

标签: android xml android-layout android-studio android-recyclerview


【解决方案1】:

这与 LayoutManager 如何计算尺寸有关。 Here 你有一些人们使用过的解决方法的相关错误。

注意:现在支持库的版本 23.2 支持包装内容,所以看起来他们修复了它。你可以查看更新日志here

【讨论】:

    【解决方案2】:

    根据您的问题,更新日期 (2016 年 3 月)

    建议你更新到Android Support Library 23.2.1以支持 RecycleVie 中的 WRAP_CONTENTw.

    在 RecyclerView 中,layout_widthwrap_content 在 23.2.1 之前不受支持。

    解决了一些问题,例如修复了与各种测量规范方法相关的错误

    查看http://developer.android.com/tools/support-library/features.html#v7-recyclerview

    【讨论】:

    • 请不要对多个问题发布相同的答案。发布一个好的答案,然后投票/标记以关闭其他问题作为重复问题。如果问题不是重复的,调整您对该问题的回答
    • 好的。我有更改我的答案的内容,并会听从您的建议。
    【解决方案3】:

    您是否尝试使用RelativeLayout 而不是线性布局,然后制作 Recyclerview layout_centerHorizontal="true"

    【讨论】:

      猜你喜欢
      • 2015-08-24
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      相关资源
      最近更新 更多