android - ListView 与 CoordinatorLayout 中的 SearchView 重叠
问题描述
我在 AndroidX 迁移后修复了一个应用程序,我遇到了一个非常奇怪的错误,即我的/ /事件ListView
没有被加载:onCreate
onStart
onResume
AndroidX 迁移后,ListView 未在 OnCreate/OnStart 上显示任何数据
偶然的机会,我决定“简化”我的布局并删除一个LinearLayout
包含ListView
. 在此更改之后,数据已正确加载,因为它似乎LinearLayout
以某种方式阻止了getView
事件。但是,在此更改之后,SearchView
被 重叠ListView
,我不知道如何将它们按正确的顺序排列(首先是 ,SearchView
然后是ListView
)。
这是它现在的样子:
这是我的代码:
other_ruins.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/search_container" />
<ListView
android:id="@+id/lstOtherRuins"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:nestedScrollingEnabled="true"
android:layout_margin="8dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:choiceMode="singleChoice"
android:layout_below="@id/toolbar_container"
android:layout_gravity="left|start" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:adSize="SMART_BANNER"
app:adUnitId="@string/banner_ad_unit_id" />
</LinearLayout>
search_container.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<FrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar_container"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:theme="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary" />
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
关于,我测试的search_containerAppBarLayout
也使用了应用程序并崩溃了;因此,这不是一个解决方案。
知道如何解决吗?为什么会这样?如果您知道如何解决上一个问题并以某种方式调用// eventsgetView
上的事件是另一种解决方案。onCreate
onStart
onResume
解决方案
当您使用inside时,您需要将FrameLayout
insearch_container.xml
替换AppBarLayout
为theAppBarLayout
Toolbar
Toolbar
CoordinatorLayout
<?xml version="1.0" encoding="UTF-8" ?>
<com.google.android.material.appbar.AppBarLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar_container"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:theme="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary" />
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.appbar.AppBarLayout>
推荐阅读
- c# - 为什么 ComputeHash 的执行速度比 certutil -hashfile 慢得多?
- perl - MULTIPLICITY 和 PERL_IMPLICIT_CONTEXT 的关系
- javascript - Wordpress - 如何从优化 JavaScript 代码中排除 google autoaddress js
- pdf - 在 Illustrator 中链接时在 windows 下使用 ggsave 生成 PDF 字体的问题
- microsoft-graph-api - 如何使用 Graph API 获取扩展属性?
- php - 是否可以访问 wordpress 主题上的 php 脚本
- javascript - 理解和转换 Ruby 的 ChunkyPNG 到 Javascript 等价物
- crm - Bitrix24 crm 上的分类自定义字段
- c# - 关闭表单时管理活动表单 C#
- ios - Xamarin.iOS 没有看到对 iOS 绑定库的引用