工具栏下方的大空间

迈克汤姆森

我尝试在两个具有的活动中使用自己的工具栏ConstraintLayout在一个活动中,我在工具栏下方放置了一个按钮,看起来不错:该图显示了良好的活动

但是,在另一个活动中,我ListView在工具栏下方放置了一个,突然之间,工具栏和ListView之间存在很大的差距:该图显示了不良活动

我应该注意,这不会出现在中的预览中AndroidStudio活动的布局完全相同,在中Manifest,我将应用程序主题设置为NoActionBar

我很高兴提供任何帮助:)

以下是“不良”活动的一些代码:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nutritionanalyzer.RecipeOverviewActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/recipe_overview_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    android:visibility="visible"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

<ListView
    android:id="@+id/recipeOverviewListView"
    android:layout_width="368dp"
    android:layout_height="495dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/recipe_overview_toolbar" />

</android.support.constraint.ConstraintLayout>

也许线

android:theme="@style/ThemeOverlay.AppCompat.ActionBar"

有罪吗?但是我在“好的”活动中有完全一样的话……

巴曼

只需android:layout_height="0dp"在ListView中进行设置,因为当您将约束布局中的子项的宽度和高度设置为零以外的其他值时,该子项的锚点边缘将居中,因为您已设置了这些属性(锚点视图的顶部和底部边缘):

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recipe_overview_toolbar" />

我想如果您只是要设置android:layout_width="0dp"此属性,您还希望listView匹配父级宽度,因为您在listView中具有这些属性(将listView水平锚定到父级):

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

并删除:

app:layout_constraintHorizontal_bias="1.0"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章