layout_weight在滚动视图中不起作用

时间:2016-07-25 13:45:36

标签: android

我正在尝试使用此代码但是当我放置布局权重时它不起作用。如果我删除布局权重并输入图像视图的高度,它工作正常。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10">

    <ImageView
        android:id="@+id/informative_image_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3.7"
        android:scaleType="fitXY"></ImageView>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view_option_menu"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6.3" />
</LinearLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:0)

实际上你不需要scrollview。去掉它。如果您在scrollview中使用recyclelerview,那么您需要在列表的dp中指定高度以使其正常工作。