簡體   English   中英

ScrollView線性布局后的布局內容未顯示

[英]Layout content after ScrollView Linear Layout not showing

我的MainActivity.xml上有整頁ScrollView線性布局。 現在,我想在ScrollView布局之后添加Admob橫幅廣告布局,以使我的橫幅在底部保持粘性。 但是在ScrollView布局之后,無論我添加什么,都不會顯示任何內容。 如果我在ScrollView中投放橫幅廣告代碼,則可以使用,但是我需要將其放置在scrollview布局之后。 我想要ScrollView layout_height =“ wrap_content”,因為設備之間的高度/寬度會有所不同。 需要別人的幫助。 我的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沒有大小,但是有權重,因此所有剩余空間(即父母身高減去adviews身高)都分配給ScrollView。

AdView刪除android:layout_weight屬性,並將其高度保留在wrap_content

ScrollView的高度更改為0dp並保持android:layout_weight處於打開狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM