首页 > 解决方案 > 我的列表视图显示在应用标签上。如何解决这个问题..?

问题描述

我创建了一个活动,我想在其中显示消息的收件箱。为此,我创建了布局。在该布局中,我的列表视图显示在应用标签上。请有人帮我解决这个问题..

我试图调整布局蓝图中的列表视图,但它只是从底部移动。

文件

<?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>

预期的

Listview 出现在应用标签下方。

实际的

实际图像

标签: androidandroid-layout

解决方案


  • 我认为你可以在 CoordinatorLayout 之后使用相对布局所以它会安排子视图显示。

例子 :-

<?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" />

只需替换上面的布局它肯定会工作。

注意:-您可以删除您的 CoordinatorLayout,因为它在这里没用,直接尝试 Relativelayout。或任何其他布局,例如:- Linearlayout , ConstraintLayout 等...


推荐阅读