我刚开始遇到这个奇怪的问题。
事件摘要:
正在以编程方式填充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>
logcat的:
// 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
哪里可能是错误?
答案 0 :(得分:2)
我觉得我不需要相对布局(根据相对布局内部的布局),而是将其更改为线性布局。这解决了这个问题。 我怀疑在加载广告后,包含AdView的LinearLayout获得了一些内容后,布局的构造遇到了一些问题。这导致ScrollView丢失了RelativeLayout中的所有空间。