0

I have created an activity in which I want to show inbox of the messages.For that I have created the layout.In that layout my list view is showing over the app label.Kindly someone help me how to fix this..

I have tried to adjust the listview in the blueprint of the layout but its only moving from the bottom.

XML FILE

<?xml version="1.0" encoding="utf-8"?><!-- Use DrawerLayout as root container for activity -->
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawerLayout"
                                           android:layout_width="match_parent"
                                           android:layout_height="match_parent"
                                           android:fitsSystemWindows="true">

<androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                                       xmlns:local="http://schemas.android.com/apk/res-auto"
                                       android:id="@+id/toolbar"
                                       android:layout_width="match_parent"
                                       android:layout_height="wrap_content"
                                       android:background="?attr/colorPrimary"
                                       android:minHeight="?attr/actionBarSize"
                                       app:contentInsetEnd="0dp"
                                       app:contentInsetStart="0dp"
                                       local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                                       local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                                       tools:ignore="RedundantNamespace"/>

    <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
    <ListView
            android:id="@+id/sms_list_view"
            android:layout_width="match_parent"
            android:layout_height="766dp"/>

    <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@id/toolbar" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

<!-- Container for contents of drawer - use NavigationViewActivity to make configuration easier -->
<com.google.android.material.navigation.NavigationView
        android:id="@+id/navigationView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:itemIconTint="@color/navigation_icon_color_state"
        app:menu="@menu/drawer_items" />

</androidx.drawerlayout.widget.DrawerLayout>

Expected

Listview appears below the app label.

Actual

actual image

Bhaven Shah
  • 692
  • 1
  • 5
  • 18
  • 1
    make listview start to the bottom of the toolbar – Abdul Aug 21 '19 at 05:19
  • app:layout_constraintTop_toBottomOf="@id/toolbar" add this to the listview xml file – Abdul Aug 21 '19 at 05:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198217/discussion-between-abdul-and-a-local-nobody). – Abdul Aug 21 '19 at 05:50

3 Answers3

0

just add : android:layout_marginTop="56dp"

    <ListView
        android:layout_marginTop="56dp"
        android:id="@+id/sms_list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

Just have to add a top margin. margins are the empty spacing between components

See here: Difference between a View's Padding and Margin

and here: http://android4beginners.com/2013/07/lesson-2-2-how-to-use-margins-and-paddings-in-android-layout/

the standard size of a toolbar is 56dp so adding a margin of 56 should be fine : https://material.io/design/components/app-bars-top.html#specs

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
0

Hey there you might have used CoordinatorLayout instead of ConstraintLayout and missed some attributes.

Try this it will help you to resolve your problem.

<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<androidx.drawerlayout.widget.DrawerLayout
        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:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                app:contentInsetEnd="0dp"
                app:contentInsetStart="0dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                tools:ignore="RedundantNamespace"/>

        <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
        <ListView
                android:id="@+id/sms_list_view"
                android:layout_width="match_parent"
                android:layout_height="766dp"
                app:layout_constraintTop_toBottomOf="@id/toolbar"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>

        <FrameLayout
                android:id="@+id/frameLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@id/toolbar"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

    <!-- Container for contents of drawer - use NavigationViewActivity to make configuration easier -->
    <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:itemIconTint="@color/navigation_icon_color_state"
            app:menu="@menu/drawer_items"/>

</androidx.drawerlayout.widget.DrawerLayout>
Arbaz Pirwani
  • 935
  • 7
  • 22
0
  • I think you can use relative layout after CoordinatorLayout So it will arrange child's view to show.

Example :-

<?xml version="1.0" encoding="utf-8"?><!-- Use DrawerLayout as root container for activity -->
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:local="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp"
            local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            tools:ignore="RedundantNamespace" />

        <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
        <ListView
            android:id="@+id/sms_list_view"
            android:layout_width="match_parent"
            android:layout_height="766dp"
            android:layout_below="@id/toolbar" />

        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@id/toolbar"
            android:layout_alignParentBottom="true" />

    </RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

<!-- Container for contents of drawer - use NavigationViewActivity to make configuration easier -->
<com.google.android.material.navigation.NavigationView
    android:id="@+id/navigationView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/navigation" />

Just Replace above layout It will work definitely.

Note :- You can remove your CoordinatorLayout because it is useless here and try directly Relativelayout. Or any other layout like :- Linearlayout , ConstraintLayout etc...

Bhaven Shah
  • 692
  • 1
  • 5
  • 18