ScrollView不会在relativelayout中显示

时间:2015-03-24 06:08:55

标签: android xml scrollview

这是我想要实现的:

enter image description here

广告视图的展示次数可以切换为可见或已消失。这是我使用的布局,没有两个按钮就可以使用。

这是带有滚动视图和广告视图的xml,没有按钮。 (scrollview工作)

<RelativeLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
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">

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"

    android:visibility="visible" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/adView"

    android:paddingBottom="12dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="12dp">

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="18dp"
        android:layout_marginRight="18dp"
        android:layout_marginTop="0dp"

        android:stretchColumns="0">

        <TableRow>
            //scrollable content here
        </TableRow

    </TableLayout>

</ScrollView>

我尝试通过将adView元素封装在TableLayout中来实现方案A,因此我可以尝试使用TableRows来实现按钮。

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tableLayout">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"

        android:visibility="visible" />

    </TableLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/tableLayout"
    .....

当我使用这种方法时,我的scrollview消失了。我哪里出错了,如何解决这个问题并进入方案A?

1 个答案:

答案 0 :(得分:0)

您在AdView中缺少TableLayout中的属性'android:layout_alignParentBottom =“true”'。这会将表格放在父级相对布局的顶部,尽管您打算将其放在底部。