簡體   English   中英

如何使這些物品永遠不會進入不同屏幕尺寸的其他物品中?

[英]How to make the items never get inside with other in different screen sizes?

我正在嘗試將webview和admob橫幅放在一個xml中,但問題是當我將它們弄混時,我在另一台屏幕大小不同的設備中將其打開。 這是我的XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.median1.psalmsmarket.Psalms">

    <WebView
        android:id="@+id/Pslamsview"
        android:layout_width="match_parent"
        android:layout_height="1400px" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="450dp"></com.google.android.gms.ads.AdView>

</RelativeLayout>

並且如果您看到我以720 * 1280的尺寸打開此應用程序時,它會以正常方式顯示,不會引起混淆

在此處輸入圖片說明

但是當我用不同的尺寸打開它時 在此處輸入圖片說明

不要使用固定大小。 如果您使用的是相對布局,那么這是確保首選輸出的最佳方法-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.median1.psalmsmarket.Psalms">

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

    <WebView
        android:id="@+id/Pslamsview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/adView"/>
</RelativeLayout>

移除您的高度1400px ,使其為match_parent然后將webview設置為高於adView android:layout_above="@+id/adView"

<WebView
        android:id="@+id/Pslamsview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/adView" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.median1.psalmsmarket.Psalms">

<WebView
    android:id="@+id/Pslamsview"
    android:layout_width="match_parent"
      android:layout_height="match_parent"
    android:layout_above="@+id/adView" />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="450dp"></com.google.android.gms.ads.AdView>

你的變化高度webviewandroid:layout_height="match_parent"並添加此屬性android:layout_above="@+id/adView"

您可以將布局從Relative更改為LinearLayout ,使用線性布局可以使用weightSum概念和layout_weight ,由此視圖在所有屏幕上的間距均等。

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1"
    tools:context="com.example.median1.psalmsmarket.Psalms">
    <WebView
        android:id="@+id/Pslamsview"
        android:layout_width="match_parent"
        android:layout_height="0"
        android:layout_weight="1"  />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="450dp"></com.google.android.gms.ads.AdView>

</RelativeLayout>

暫無
暫無

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

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