布局在不同的智能手机中无法正确显示



我无法在智能手机中显示XML文件,因为它在Android工作室中显示的。在某些智能手机中,广告下方的底部空间为空白,而在某些智能手机中,底部空间可以正确显示。

请更正我的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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Version">
<ScrollView
android:layout_width="match_parent"
android:layout_height="470dp">
<TextView
android:id="@+id/tV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:scrollbars="vertical"
android:text="@string/version"
android:textColor="@color/black"
android:textSize="19sp"
app:fontFamily="sans-serif-condensed-light">
</TextView>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white">

<Button
android:id="@+id/zoomout"
android:layout_width="38dp"
android:layout_alignParentStart="true"
android:layout_height="38dp"
android:background="@drawable/zoom_out"
android:layout_alignParentLeft="true">
</Button>
<Button
android:id="@+id/trans_punjabi"
android:layout_width="38dp"
android:layout_toLeftOf="@id/zoonin"
android:layout_height="38dp"
android:background="@drawable/translation"
></Button>

<SeekBar
android:id="@+id/seekBar"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="45dp"
android:layout_marginLeft="13dp"
android:layout_marginRight="45dp"
android:layout_marginStart="13dp"
android:layout_toEndOf="@+id/zoomout"
android:layout_toLeftOf="@+id/zoonin"
android:layout_toRightOf="@+id/zoomout"
android:layout_toStartOf="@+id/zoonin" />
<Button
android:id="@+id/zoonin"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:background="@drawable/zoom_in"
android:layout_alignParentRight="true">
</Button>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center"
android:background="@color/white">
<Button
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="13dp"
android:layout_marginStart="13dp"
android:layout_toEndOf="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:background="@drawable/forward" />
<Button
android:id="@+id/button2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="-3dp"
android:layout_marginStart="-3dp"
android:layout_toEndOf="@+id/button"
android:layout_toRightOf="@+id/button"
android:background="@drawable/pauses" />
<Button
android:id="@+id/button3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/button2"
android:background="@drawable/plays" />
<Button
android:id="@+id/button4"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="3dp"
android:layout_toRightOf="@+id/button3"
android:background="@drawable/rewind" />
<TextView
android:id="@+id/textView2"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:foregroundGravity="clip_horizontal"
android:gravity="clip_horizontal|center"
android:paddingLeft="14dp"
android:text="0:0"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="24sp" />
<TextView
android:id="@+id/textView1"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_toRightOf="@id/button4"
android:foregroundGravity="center_vertical"
android:gravity="center_horizontal"
android:paddingRight="14dp"
android:text="5:23"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="24sp" />
</RelativeLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</LinearLayout>

我希望文本视图(它是一个带有滚动的长文本)显示在顶部,广告显示在底部,底部不应该有空格。

您的问题是您具有线性垂直布局,其中包含一个固定大小的小部件(ScrollView)和很少的wrap_content- 这些值的总和(测量后)也是固定的大小/高度,因此在某些设备上(尤其是大)它将小于可用空间。 尽量避免像这样固定大小的声明:android:layout_height="470dp", 特别是对于ViewViewGroup/父母

使用RelativeLayout作为根布局,内部使用layout_abovelayout_alignParentBottomlayout_alignParentAbove属性

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
.../>
<RelativeLayout
android:id="@+id/buttons_lower_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/adView"
.../>
<RelativeLayout
android:id="@+id/buttons_upper_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/buttons_lower_row"
.../>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@id/buttons_upper_row"
android:layout_alignParentTop="true"
.../>
</RelativeLayout>

放置在底部(AdView)的View首先声明。 然后下一个View(ad 上面的一个)声明为android:layout_above="@id/adView",依此类推。 最后ScrollView既有layout_above又有layout_alignParentTop- 适合左侧空白

附言。layout_above=<id>你能想象到像this_layout_should_be_above_layout_with_id=<id>,还有layout_belowlayout_toRightOflayout_toLeftOf。所有这些都在RelativeLayoutView的边缘到边缘对齐

我想为您的小部件设置固定大小,您可以使用此库。它将根据屏幕尺寸缩放小部件。

最新更新