android - AdView doesn't show ads at the bottom of the linear layout layout -Why So?
问题描述
I'm trying to show admob adview at the bottom of the screen but it doesn't work. It shows ad below the text if the text is short (doesn't need to scroll) , but if the text is long (need to scroll) the adview doesn't show at all. I want to show the adview at the bottom of my screen no matter how long or short the text is. I have been at this for hours but couldn't figure out to make it work.
Here is my Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="@color/backgroundColor"
tools:context=".activities.DetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:elevation="1.46dp"
android:background="@color/backgroundColor">
<TextView
android:id="@+id/tvWordDetail"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="@color/textColorPrimary"
android:textSize="20sp"
android:gravity="center_vertical"/>
<ImageButton
android:id="@+id/textToSpeech"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/text_to_speech"
android:background="?actionBarItemBackground"
app:srcCompat="@drawable/ic_volume"/>
<ImageButton
android:id="@+id/btnBookmark"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/add_bookmark"
android:background="?actionBarItemBackground"
app:srcCompat="@drawable/ic_bookmark_border"/>
</LinearLayout>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/viewColor"/>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/backgroundColor"
android:elevation="1.46dp"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingTop="10dp"
android:paddingRight="16dp">
<TextView
android:id="@+id/tvWordDefinition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/textColorSecondary"
android:textSize="18sp" />
</LinearLayout>
</ScrollView>
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/admob_banner_ad_detail">
</com.google.android.gms.ads.AdView>
</LinearLayout>
解决方案
添加一个新属性android:layout_weight="1" 并修改滚动视图的高度,如下所示。
android:layout_height="0dp"
android:layout_weight="1"
所以滚动视图的最终属性集看起来像,
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
推荐阅读
- apache - cURL vs ab performance testing
- msbuild - 如何解压缩 zip 文件并从中导入 smth 作为构建的一部分?
- flutter - what is the sink in streamcontroller in flutter
- amazon-web-services - 有没有办法按需重新运行 AWS Security Hub CIS 基准?
- git - 更改为 .gitattributes 后 Git 重新签出文件
- reactjs - 如何对使用 Enzyme 在 useEffect 中获取数据的反应钩子组件进行单元测试?
- python - 使用“df.sample(frac=1)”后如何删除添加的列?
- swift - SwiftUI:设置工作表呈现视图的背景颜色
- azure - 如何设置 Azure 重试策略异常?
- documentum - 如何恢复用户配置文件夹下丢失的 Documentum 文件夹 (UCF)?