android - Android API 21 上缺少包含的布局
问题描述
我有一个应用程序已经在我的设备上运行了很长时间。今天我决定在旧设备上测试它。我有一个旧的 Glaxy S4 Mini,所以我把它加载了,我的布局的整个部分都丢失了。缺少的部分是我制作的可重用布局,并将其包含在此活动中。它所在的空间没有被任何东西占据,它只是空着
这是活动布局文件。当应用程序运行时,里面的所有东西都include
完全丢失了。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.eddie.songsPrimirenya.SearchActivityReg">
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search_bar_include"
layout="@layout/search_bar"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/RecyclerViewReg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="@+id/search_bar_include"
android:layout_margin="3dp"/>
</RelativeLayout>
这是我之前包含的布局。我认为由于某些兼容性问题它没有显示,但我不知道它是什么。
<?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">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardSearchReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
card_view:cardCornerRadius="5dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintVertical_bias="0.0">
<RelativeLayout
android:id="@+id/LayoutAll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/LayoutSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/txtInReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:hint="@string/search"
android:singleLine="true"
android:textColorHint="@color/textHint" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/LayoutSearchModeSelect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/LayoutSearch"
android:layout_marginStart="3dp">
<Switch
android:id="@+id/swtSearchType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="false"
android:text="@string/search_by_name"
android:textColorHighlight="@color/colorAccent"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
解决方案
使您的包含布局匹配父级,它应该可以正常工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.eddie.songsPrimirenya.SearchActivityReg">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search_bar_include"
layout="@layout/search_bar"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/RecyclerViewReg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="@+id/search_bar_include"
android:layout_margin="3dp"/>
</RelativeLayout>
推荐阅读
- c# - 错误:更新数据库命令后表 'Table_name' 已存在
- java - 如何读取 .properties 文件中的当前项目路径
- node.js - 我是否必须在需要使用 npm 命令的 bitbucket 管道中的每个步骤中安装 npm
- c# - 如何解释我的方法的参数是“null”而不是“int”
- android - 无法打开从 xamarin.forms 中的 byte[] 下载的文件
- javascript - API调用中的错误处理更改问题
- c# - 如何在 ASP.NET MVC 5 上公开 WS-Federation 元数据?
- elasticsearch - 使用 groupby 并具有等效功能的弹性搜索查询
- c# - 如何使用 powershell 控制台自动化 C# 应用程序?
- html - 不再工作