片段中的布局不是全屏

时间:2020-05-03 09:15:42

标签: android android-studio android-layout android-fragments

我不知道为什么,但是即使我在代码和xml布局中设置了布局参数,我片段中的布局或内容也无法填充父项。有谁对此有解决方案。提前致谢。 我的片段的图像如下。 enter image description here

显示的图像是用recyclerview完成的 recyclerview。 XML文件 recyclerviewlayout.xml fragment_items。 XML文件 itemsfragment.xml ItemsFragment的onCreateView。 Java类 onCreateView of ItemsFragment.java class

2 个答案:

答案 0 :(得分:0)

ConstraintLayout允许您创建具有平面视图层次结构(无嵌套视图组)的大型复杂布局。

  • 使用0dp,相当于“ MATCH_CONSTRAINT”

您的RecyclerView将是(尊重ConstraintLayout)

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    >

答案 1 :(得分:0)

如果您只在fragment_items中包含recyclerview,则可以使用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_videos"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        />

</LinearLayout>