无法判断这个额外的空间边界来自哪里,没有改变任何东西,除了从listfragmwent到fragment的java片段,并在布局文件中取出了一个列表视图,转而使用RecyclerView。边界空白是一个谜,因为它以前不存在。我没有在片段中设置边距,唯一的填充集在项目中留有填充
片段xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/white"
android:orientation="vertical"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="350dp"
android:layout_height="501dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.58"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1"
tools:layout_editor_absoluteX="-13dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_newPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
app:srcCompat="@drawable/ic_action_create_post"
app:elevation="3dp"
app:pressedTranslationZ="6dp"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="15dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp" />
<ProgressBar
style="@style/Base.Widget.AppCompat.ProgressBar"
android:id="@+id/progress_user_posts"
android:visibility="invisible"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:indeterminate="true"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="150dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" />
</android.support.constraint.ConstraintLayout>
item xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/row_post_username"
android:layout_width="261dp"
android:layout_height="18dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:paddingLeft="0dp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="16dp"
tools:layout_conversion_absoluteWidth="360dp"
tools:layout_conversion_absoluteX="0dp"
tools:layout_conversion_absoluteY="10dp" />
<TextView
android:id="@+id/row_post_time"
android:layout_width="79dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/row_post_username"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
tools:layout_editor_absoluteX="264dp" />
<TextView
android:id="@+id/row_post_content"
android:layout_width="353dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:paddingLeft="30dp"
android:paddingTop="7dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/row_post_username"
tools:layout_conversion_absoluteHeight="16dp"
tools:layout_conversion_absoluteWidth="360dp"
tools:layout_conversion_absoluteX="0dp"
tools:layout_conversion_absoluteY="26dp"
tools:layout_editor_absoluteY="34dp" />
<View
android:id="@+id/divider_post"
android:layout_width="360dp"
android:layout_height="1dp"
android:background="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/row_post_content"
tools:layout_conversion_absoluteHeight="1dp"
tools:layout_conversion_absoluteWidth="344dp"
tools:layout_conversion_absoluteX="8dp"
tools:layout_conversion_absoluteY="61dp"
android:layout_marginTop="18dp"
app:layout_constraintHorizontal_bias="0.0" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:1)
您的RecyclerView具有固定的宽度和高度:
android:layout_width="350dp"
android:layout_height="501dp"
替换为 match_parent 以使用所有空格:
android:layout_width="match_parent"
android:layout_height="match_parent"
然后用:
设置所需的保证金android:layout_margin="10dp"