【发布时间】:2016-11-05 17:18:53
【问题描述】:
基本上,我有两个相似的布局,但创建方法不同。问题是 RecyclerView WRAP_CONTENT 在这两种布局上的行为不同。在第一个布局中它可以正常工作,而在其他布局中,WRAP_CONTENT 不起作用。
下面的代码不起作用。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
... other layout codes
<android.support.v7.widget.RecyclerView
android:id="@+id/xxx"
style="@style/MarginLeftDetail"
android:layout_width="match_parent"
android:layout_height="0dp"
/>
... other layout codes
</LinearLayout>
虽然这是一个有效的方法。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
... other layout codes
<android.support.v7.widget.RecyclerView
android:id="@+id/xxx"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/yyy"
style="@style/MarginLeftDetail"
android:layout_marginTop="7.5dp"/>
... other layout codes
</RelativeLayout>
LinearLayout 对 WRAP_CONTENT 的解释是否与 RelativeLayout 不同?
更新:如果我用RelativeLayout 包装第一个RecyclerView,它工作正常。所以我猜LinearLayout 真的对WRAP_CONTENT 有不同的解释吗?还是bug?
谢谢。
【问题讨论】:
-
您必须提供更多问题详情。您可以发布线性和相对布局的屏幕截图吗?
标签: android android-layout android-recyclerview android-linearlayout