【发布时间】:2015-02-11 23:23:05
【问题描述】:
我开发了一个可以在 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 21
有什么想法吗?非常感谢任何帮助。
编辑:我尝试添加行 findViewById(R.id.card_viewrunning).setVisibility(View.VISIBLE);没有占上风。
再一次,这在 api 21 设备上完美运行。很奇怪的一个。
【问题讨论】:
-
代码在哪里?你在改变可见性吗?
-
我实际上只是夸大了视图。我刚刚检查过,我什至没有通过 id 明确提及 card 元素。
-
您在预览版或模拟器设备中也遇到过这个问题?
-
预览和实际设备上。设备上会短暂显示,然后消失。
标签: android android-layout android-studio android-cardview