ScrollView 线性布局后的布局内容不显示
Layout content after ScrollView Linear Layout not showing
我的 MainActivity.xml 上有整页 ScrollView 线性布局。现在我想在 ScrollView 布局之后添加 Admob 横幅广告布局,以便我的横幅在底部保持粘性。但是在 ScrollView 布局之后,无论我添加什么,都不会显示任何内容。如果我在 ScrollView 中插入横幅广告代码,它可以工作,但我需要将它放在 scrollview 布局之后。我想要 ScrollView layout_height="wrap_content",因为设备之间 height/width 各不相同。需要别人的帮助。我的 xml 代码如下:
<?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>
将 ScrollViews 高度设置为 0dp
并移除 AdView 上的权重(您也可以移除其 LinearLayout 包装器)
之所以有效,是因为; AdView 有自己的大小 (wrap_content)。 ScrollView没有大小,但是有权重,所以剩下的space(即parents高度减去adviews高度)全部赋值给ScrollView。
从 AdView
中删除 android:layout_weight
属性并将其高度保留在 wrap_content
将 ScrollView
的高度更改为 0dp
并保留 android:layout_weight
。
我的 MainActivity.xml 上有整页 ScrollView 线性布局。现在我想在 ScrollView 布局之后添加 Admob 横幅广告布局,以便我的横幅在底部保持粘性。但是在 ScrollView 布局之后,无论我添加什么,都不会显示任何内容。如果我在 ScrollView 中插入横幅广告代码,它可以工作,但我需要将它放在 scrollview 布局之后。我想要 ScrollView layout_height="wrap_content",因为设备之间 height/width 各不相同。需要别人的帮助。我的 xml 代码如下:
<?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>
将 ScrollViews 高度设置为 0dp
并移除 AdView 上的权重(您也可以移除其 LinearLayout 包装器)
之所以有效,是因为; AdView 有自己的大小 (wrap_content)。 ScrollView没有大小,但是有权重,所以剩下的space(即parents高度减去adviews高度)全部赋值给ScrollView。
从 AdView
中删除 android:layout_weight
属性并将其高度保留在 wrap_content
将 ScrollView
的高度更改为 0dp
并保留 android:layout_weight
。