簡體   English   中英

Android API 21缺少包含的布局

[英]Included layout missing on 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM