[英]How to make the items never get inside with other in different screen sizes?
i'm trying to put webview and admob banner in one xml but the thing is when i do they get mixed up i opened it in another device with different screen size. 我正在尝试将webview和admob横幅放在一个xml中,但问题是当我将它们弄混时,我在另一台屏幕大小不同的设备中将其打开。 this is my 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>
and if you seen when i open this application with size 720*1280 it show in normal way they dont get mixed 并且如果您看到我以720 * 1280的尺寸打开此应用程序时,它会以正常方式显示,不会引起混淆
but when i open it with a different size that will happens 但是当我用不同的尺寸打开它时
Do not use fix size. 不要使用固定大小。 If you are using Relative Layout then this is the best way to ensure the preferred output -
如果您使用的是相对布局,那么这是确保首选输出的最佳方法-
<?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>
Remove your hard height 1400px
and make it match_parent
then set the webview to be above the adView android:layout_above="@+id/adView"
移除您的高度
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>
Change height of your webview
to android:layout_height="match_parent"
and add this property android:layout_above="@+id/adView"
你的变化高度
webview
到android:layout_height="match_parent"
并添加此属性android:layout_above="@+id/adView"
You can change your layout from Relative to LinearLayout
, with linear layout you can use weightSum
concept and layout_weight
, with this the view will get equally spaced in all screens . 您可以将布局从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.