我创建了一个活动,我想在其中显示消息的收件箱。为此,我创建了布局。在该布局中,列表视图显示在应用标签上方。请帮助我解决此问题。
我试图在布局的蓝图中调整列表视图,但它仅从底部移动。
XML文件
<?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出现在应用程序标签的下方。
实际
答案 0 :(得分:0)
只需添加:(defn merge-maps
[& args]
(let [max-count (apply max (map #(count %1) args))
items (map #(take max-count (concat %1 (repeat nil))) args)]
(apply map merge items)))
android:layout_marginTop="56dp"
只需添加顶部边距。边距是组件之间的空白
请参见此处:Difference between a View's Padding and Margin
在这里: http://android4beginners.com/2013/07/lesson-2-2-how-to-use-margins-and-paddings-in-android-layout/
工具栏的标准大小为56dp,因此添加56的边距应该没问题:https://material.io/design/components/app-bars-top.html#specs
答案 1 :(得分:0)
嘿,您可能使用了CoordinatorLayout
而不是ConstraintLayout
并错过了一些属性。
尝试此操作将帮助您解决问题。
<?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>
答案 2 :(得分:0)
示例:-
<?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等...