CardView在API 19上消失了

时间:2015-02-11 23:23:05

标签: android android-layout android-studio android-cardview

我开发了一款适用于Lollipop的应用程序。但是,我在kitkat(api 19)上遇到了一些奇怪的故障

当我在kitkat设备上运行我的应用程序时,它会在一瞬间显示我的卡片视图然后消失。

下面的

是我的xml布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:bootstrap="http://schemas.android.com/apk/res-auto"
    xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context="com.running.mattboyle.runnertoolbox.RunningMap">


    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_viewrunning"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"

        android:background="@drawable/backgroundcard"
        card_view:cardCornerRadius="4dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Chronometer
            android:id="@+id/Duration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="16dp"
                android:paddingLeft="10dp"
            android:text="0:00"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <TextView
            android:id="@+id/Calories"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="14dp"
            android:layout_marginTop="60dp"
            android:text="Calories: 0" />
        <TextView
            android:id="@+id/pace"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
            android:layout_alignParentRight="true"
            android:text="0:00"
            android:layout_marginEnd="60dp" />

            <TextView
            android:id="@+id/paceunits"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
                android:text="min/km"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="10dp" />

            <TextView
                android:id="@+id/distanceText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignStart="@id/Duration"
                android:layout_marginTop="52dp"
                android:text="0.00"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/distanceUnits"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/Duration"
                android:layout_marginTop="12dp"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@id/distanceText"
                android:text="KM"
                android:textAppearance="?android:attr/textAppearanceMedium" />


        </RelativeLayout>


    </android.support.v7.widget.CardView>

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <com.beardedhen.androidbootstrap.BootstrapButton
        android:id="@+id/runButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:text="Begin Run"
            android:layout_centerInParent="true"

        bootstrap:bb_type="primary" />


    <com.beardedhen.androidbootstrap.BootstrapButton
        android:id="@+id/pauseButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="5dp"
        android:text="Pause"
        android:layout_centerHorizontal="true"
        android:paddingRight="120dp"
        bootstrap:bb_type="warning" />

    <com.beardedhen.androidbootstrap.BootstrapButton
        android:id="@+id/EndButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="5dp"
        android:layout_centerInParent="true"
        android:layout_centerHorizontal="true"
        android:paddingLeft="120dp"

        android:text="End Run"
        bootstrap:bb_type="success"

        />
    </RelativeLayout>

    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true"
        android:paddingBottom="40dp">

        <com.beardedhen.androidbootstrap.BootstrapButton
            android:id="@+id/right"
            android:layout_width="70dp"
            android:layout_margin="10dp"

            android:layout_height="wrap_content"
            bootstrap:bb_type="primary"
            fontawesometext:fa_icon="fa-forward"
            android:text="Next"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="10dp" />

        <TextView
            android:layout_marginTop="15dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Calculating....."
            android:id="@+id/runLength"
            android:layout_centerHorizontal="true" />


        <com.beardedhen.androidbootstrap.BootstrapButton
            android:layout_width="70dp"
            android:layout_height="wrap_content"
            bootstrap:bb_type="primary"
            android:text="Last"
            fontawesometext:fa_icon="fa-backward"
            android:id="@+id/left"
            android:layout_alignParentLeft="true"
            android:layout_marginStart="10dp" />


    </RelativeLayout>

</RelativeLayout>


What's extra weird is I have a cardview on my home screen too that opens and works just fine:

      <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:background="@drawable/backgroundcard"
            card_view:cardCornerRadius="4dp">

            <RelativeLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:divider="@drawable/vertical_divider"
                android:dividerPadding="12dip"
                android:showDividers="middle">

                <TextView
                    android:id="@+id/weather"
                    android:textColor="@android:color/primary_text_light"

                    android:paddingTop="10dp"
                    android:paddingLeft="15dp"

                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="Weather"
                    android:textSize="25dp"

                    />

                <TextView
                    android:id="@+id/location"
                    android:textColor="@android:color/darker_gray"

                    android:paddingTop="130dp"
                    android:paddingLeft="40dp"

                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="Birmingham,UK"

                    />


                <ImageView
                    android:layout_width="130dp"
                    android:layout_height="130dp"
                    android:background="@drawable/nightcloud"
                    android:layout_marginTop="25dp"
                    android:layout_marginLeft="20dp"
                    android:layout_centerVertical="true"

                    android:id="@+id/weatherImage" />


                <TextView
                    android:id="@+id/low"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="05\u00B0"
                    android:paddingTop="75dp"
                    android:paddingRight="20dp"
                    android:layout_alignParentEnd="true"
                    android:textColor="@android:color/primary_text_light"


                    />

                <TextView
                    android:id="@+id/high"
                    android:textColor="@android:color/primary_text_light"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="10\u00B0"
                    android:paddingTop="95dp"
                    android:paddingRight="20dp"
                    android:layout_alignParentEnd="true" />

                <TextView
                    android:id="@+id/current"

                    android:textColor="@android:color/darker_gray"
                    android:textSize="50dp"

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="10\u00B0"

                    android:paddingRight="50dp"
                    android:layout_centerVertical="true"
                    android:layout_alignParentEnd="true" />

                <TextView
                    android:id="@+id/judgement"


                    android:paddingTop="10dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/darker_gray"

                    android:text="Wear an underlayer, it is cold!"
                    android:paddingBottom="5dp"
                    android:paddingLeft="15dp"

                    android:layout_alignParentBottom="true"
                    android:layout_alignParentStart="true" />
            </RelativeLayout>

        </android.support.v7.widget.CardView>

Log cat不提供任何投诉。

Android Studio也记录了这一点:

api 19 Api 19

api 21 api 21

有什么想法吗?非常感谢任何帮助。

编辑:我尝试添加行findViewById(R.id.card_viewrunning).setVisibility(View.VISIBLE);没有优势。

再一次,这在api 21设备上完美运行。非常奇怪的一个。

1 个答案:

答案 0 :(得分:3)

查看android studio右侧的组件树选项卡,了解您在v19中的布局。选择您的cardview并在可视化编辑器上查看,它应该突出显示。我的猜测是隐藏在片段后面。

相关问题