Android 使用linearlayout填充空间的其余部分

Android 使用linearlayout填充空间的其余部分,android,android-layout,Android,Android Layout,我有一个底部有一个CardView。我希望cardwiew的高度至少为120dp,并填充剩余空间(因此我将其layout\u weight设置为1) FoodCardFragment被放入(的第一个选项卡),并且它的layout\u权重设置为1,因为我希望它填充剩余的空间 但是,从我在下面发布的图片中可以看出,我上面提到的黄色cardwiew并没有填满剩余的空间。我怎样才能实现我的目标 如果链接不起作用: FoodCardFragment的代码: <LinearLayout xmlns:

我有一个底部有一个
CardView
。我希望
cardwiew
的高度至少为120dp,并填充剩余空间(因此我将其
layout\u weight
设置为1)

FoodCardFragment
被放入(的第一个选项卡),并且它的
layout\u权重设置为1,因为我希望它填充剩余的空间

但是,从我在下面发布的图片中可以看出,我上面提到的黄色
cardwiew
并没有填满剩余的空间。我怎样才能实现我的目标

如果链接不起作用:

FoodCardFragment的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    android:background="@android:color/white">

    <android.support.v7.widget.CardView
        android:id="@+id/food_card"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:elevation="2dp">

        <android.support.constraint.ConstraintLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/food_image"
                android:layout_width="320dp"
                android:layout_height="320dp"
                android:scaleType="centerCrop"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/food_image_place_holder" />

            <ImageView
                android:id="@+id/liked_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="4dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_undo_like" />
        </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.CardView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">

        <TextView
            android:id="@+id/food_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textSize="24sp"
            android:textStyle="bold"
            android:layout_weight="1"
            android:maxLines="1"
            android:ellipsize="end"
            android:layout_marginEnd="4dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/food_card" />

        <ImageButton
            android:id="@+id/more_button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_dropdown" />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/tags_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginVertical="10dp" />

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:minHeight="120dp">
        <TextView
            android:id="@+id/food_note_back"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/food_note_background"
            android:scrollbars="vertical"
            android:paddingTop="4dp"
            android:paddingBottom="4dp"
            android:paddingHorizontal="8dp" />

        <TextView
            android:id="@+id/food_note_front"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/food_note_background"
            android:scrollbars="vertical"
            android:paddingTop="4dp"
            android:paddingBottom="4dp"
            android:paddingHorizontal="8dp" />
    </android.support.v7.widget.CardView>

</LinearLayout>

随机片段代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/whiteSmoke">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/colorBackgroundFloating"
        android:elevation="2dp">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/title_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/random"
                android:textSize="20sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageButton
                android:id="@+id/filter_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="15dp"
                android:background="@android:color/transparent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@id/menu_button"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_filter" />

            <ImageButton
                android:id="@+id/menu_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="10dp"
                android:background="@android:color/transparent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_menu" />
        </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.Toolbar>

    <android.support.v7.widget.CardView
        android:id="@+id/food_card_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:layout_marginHorizontal="20dp"
        android:layout_marginTop="30dp"
        android:background="@android:color/white"
        app:cardCornerRadius="4dp"
        app:cardElevation="4dp">
        <FrameLayout
            android:id="@+id/food_card_frame"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </android.support.v7.widget.CardView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:padding="10dp">

        <ImageButton
            android:id="@+id/check_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:padding="8dp"
            app:srcCompat="@drawable/ic_check" />

        <ImageButton
            android:id="@+id/cross_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:padding="8dp"
            app:srcCompat="@drawable/ic_cross" />

        <ImageButton
            android:id="@+id/refresh_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:padding="8dp"
            app:srcCompat="@drawable/ic_refresh" />
    </LinearLayout>
</LinearLayout>


哪一个是您发布的xml黄色视图?@PankajKumar它是前面提到的
cardwiew
中2个
TextView
s的背景。