我刚开始遇到这个奇怪的问题。
活动总结:
正在以编程方式填充 tableLayout。一个不同的 tableLayout,其中包含一个固定的行,在这个以编程方式填充的 tableLayout 之上,包含它们的标题(4 个 textViews)。加载活动时,它看起来很完美。此外,本次活动底部的横幅广告,以及在 onCreate 中提出并在 onPause 中呈现的插页式广告请求。
问题:
一旦横幅广告显示在底部,4 个标题文本视图就会消失!由于我找不到为 textviews 设置 visibilityChangedListener 的任何方法,我为表格布局、表格行和文本视图使用了不同的颜色背景,这告诉我问题出在 textviews 上,尽管表格行在那里(对行使用触摸侦听器和颜色标记)。当我注释掉横幅广告加载语句(插页式广告仍在工作)时不会发生这种情况,当我的设备未连接到互联网时不会发生这种情况。我有一个发生这种情况的 Nexus4 (JB-4.3),但在 AVD Manager 中包含的模拟器(3.2" (GB-2.3.3))上没有问题。更有趣的是,我使用这些文本视图的唯一地方是让 layoutParams 在创建的动态文本视图中设置(看起来很好)。
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context=".DisplayAmortizationChart"
android:background="@color/layout_background">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adLayout"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:id="@+id/linearLayout"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/tvHeading"
android:text="@string/hello_world"
android:background="@color/layout_background"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/holo_purple"
android:baselineAligned="true">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
android:id="@+id/titleRow"
android:layout_marginBottom="1dp"
android:baselineAligned="true"
android:visibility="visible">
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/chartHead_serial"
android:id="@+id/tvTitleSno"
android:layout_weight="4"
android:gravity="left"
android:background="@android:color/holo_green_dark"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/chartHead_interest"
android:id="@+id/tvTitleInt"
android:layout_weight="10"
android:gravity="right"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/chartHead_principal"
android:id="@+id/tvTitlePrin"
android:layout_weight="10"
android:gravity="right"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/chartHead_outstanding"
android:id="@+id/tvTitleBal"
android:layout_weight="11"
android:gravity="right"/>
</TableRow>
</TableLayout>
</LinearLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/scrollView"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tableChart"
android:background="@android:color/black"
android:baselineAligned="true">
</TableLayout>
</ScrollView>
</RelativeLayout>
<LinearLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:id="@+id/adLayout">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="blahblahblah
ads:adSize="SMART_BANNER"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
日志猫:
// output from logcat
09-19 18:47:55.502 7804-7804/com.swarajk1.easyemicalculator D/EmiCalculatorActivity Debug Logs﹕ AmortizationChart Intent sent
09-19 18:47:55.522 7804-7804/com.swarajk1.easyemicalculator D/EmiCalculatorActivity Debug Logs﹕ onPause ActivityState written
09-19 18:47:55.602 7804-7804/com.swarajk1.easyemicalculator D/AmortizationChartActivity﹕ TableLayout construction started
09-19 18:47:55.602 7804-7804/com.swarajk1.easyemicalculator D/AmortizationChartActivity﹕ Screen density is high or more: 320
09-19 18:47:55.612 7804-7804/com.swarajk1.easyemicalculator D/AmortizationChartActivity﹕ TableLayout construction finished
09-19 18:47:55.652 7804-7804/com.swarajk1.easyemicalculator D/dalvikvm﹕ GC_FOR_ALLOC freed 554K, 6% free 9852K/10448K, paused 21ms, total 21ms
09-19 18:47:55.662 7804-7804/com.swarajk1.easyemicalculator D/AmortizationChartActivity﹕ Banner ad displayed
09-19 18:47:55.662 7804-7804/com.swarajk1.easyemicalculator D/AmortizationChartActivity﹕ Google Analytics started
09-19 18:47:55.672 7804-10166/com.swarajk1.easyemicalculator I/Ads﹕ adRequestUrlHtml: <html><head>....</head><body></body></html>
09-19 18:47:55.682 7804-10165/com.swarajk1.easyemicalculator I/Ads﹕ adRequestUrlHtml: <html><head>....</head><body></body></html>
09-19 18:47:55.942 7804-7804/com.swarajk1.easyemicalculator I/Ads﹕ Received ad url: ....
09-19 18:47:55.942 7804-10166/com.swarajk1.easyemicalculator I/Ads﹕ Request scenario: Online server request.
09-19 18:47:56.052 7804-7804/com.swarajk1.easyemicalculator D/dalvikvm﹕ GC_FOR_ALLOC freed 561K, 7% free 9802K/10448K, paused 28ms, total 28ms
09-19 18:47:56.062 7804-7804/com.swarajk1.easyemicalculator I/Ads﹕ Received ad url: ....
09-19 18:47:56.062 7804-10165/com.swarajk1.easyemicalculator I/Ads﹕ Request scenario: Online server request.
09-19 18:47:57.854 7804-7804/com.swarajk1.easyemicalculator D/webviewglue﹕ nativeDestroy view: 0x760c07f8
//this is almost when the row disappears
09-19 18:47:57.854 7804-7804/com.swarajk1.easyemicalculator I/Ads﹕ onReceiveAd()
09-19 18:47:58.145 7804-10172/com.swarajk1.easyemicalculator D/dalvikvm﹕ GC_FOR_ALLOC freed 256K, 7% free 9778K/10448K, paused 23ms, total 23ms
09-19 18:47:59.216 7804-7804/com.swarajk1.easyemicalculator D/webviewglue﹕ nativeDestroy view: 0x73f487a8
09-19 18:47:59.216 7804-7804/com.swarajk1.easyemicalculator I/Ads﹕ onReceiveAd()
09-19 18:47:59.216 7804-7804/com.swarajk1.easyemicalculator D/Interstitial Status﹕ Interstitial Ad Received
哪里可能出错?