0

我的MainActivity.xml中有一整页ScrollView线性布局。现在我想在ScrollView布局后添加Admob Banner Ad布局,这样我的旗帜就会保持粘性。但在ScrollView布局之后,无论我做什么添加,都不显示任何内容。如果我在ScrollView中广告横幅广告代码,它可以工作,但我需要将它放在滚动视图布局之后。我想要ScrollView layout_height =“wrap_content”,因为设备到设备的高度/宽度有所不同。需要某人的帮助。我的XML代码如下:ScrollView线性布局未显示后的布局内容

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/back2" 

    tools:context="com.domain.appname.MainActivity"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="match_parent" 
       android:layout_height="230dp" 
       app:srcCompat="@drawable/head" /> 


      <TextView 
       android:id="@+id/textView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="App Title" 
       android:textAlignment="center" 
       android:textSize="24sp" 
       android:textStyle="bold" 
       android:layout_marginTop="15dp" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="20dp" 
       android:text="App Description" 
       android:textSize="20sp"/> 

      <Button 
       android:id="@+id/button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:padding="15dp" 
       android:text="List Page" 
       android:layout_marginBottom="15dp" 
       android:textSize="20sp" 
       style="@style/Widget.AppCompat.Button.Colored" 
       android:onClick="switcher"/> 
     </LinearLayout>   
    </ScrollView> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      ads:adSize="SMART_BANNER" 
      ads:adUnitId="@string/banner_ad_unit_id" 
      > 
     </com.google.android.gms.ads.AdView> 
    </LinearLayout> 
</LinearLayout> 

回答

0

设置ScrollViews高度0dp和删除AdView的重量(你也可以除去它的LinearLayout包装)

这样做是因为, AdView具有自己的大小(wrap_content)。 ScrollView没有大小,但有一个重量,因此所有剩余的空间(即父母高度减去adview高度)被分配给ScrollView。

+0

Thanks @RobCo,它完美的作品:) –

0

AdView取出android:layout_weight属性和ScrollView的高度,离开它的高度在wrap_content

更改为0dp,并留在android:layout_weight