Reputation: 23
I try to use my own Toolbars in two Activities that have the ConstraintLayout
.
In one Activity, I placed a button below the toolbar, what looks fine:
However, in the other Activity, I placed a ListView
below the toolbar and suddenly there is a big gap between the Toolbar and the ListView:
I should note that this does not appear in the preview in AndroidStudio
.
The layout of the Activities is exactly the same and in the Manifest
, I set the application theme to NoActionBar
.
I am happy about any kind of help :)
Here is some of the code of the "bad" Activity:
<?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>
Maybe the line
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
is guilty? But I have exactly the same line at the "good" Activity...
Upvotes: 2
Views: 443
Reputation: 3977
just set android:layout_height="0dp"
in ListView because when you set width and height of a child in constraint layout to something other than zero and anchor edges of the child the view will be centered between anchor points because you have set these attributes (you have anchor view's top and bottom edges):
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recipe_overview_toolbar" />
I guess that you also want listView to match parent width if you want this just set android:layout_width="0dp"
because you have these attributes in listView (you have anchor listView horizontally to parent):
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
and remove:
app:layout_constraintHorizontal_bias="1.0"
Upvotes: 1