Android layout Android Studio:内容脱离屏幕

Android layout Android Studio:内容脱离屏幕,android-layout,android-studio,Android Layout,Android Studio,当安装在实际的android设备上时,我的部分UI会脱离屏幕。它使用谷歌地图API。“我的位置”按钮有点脱离屏幕 此外,即使在Android Studio的UI预览中,地图也没有覆盖整个屏幕 <LinearLayout xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content" a

当安装在实际的android设备上时,我的部分UI会脱离屏幕。它使用谷歌地图API。“我的位置”按钮有点脱离屏幕

此外,即使在Android Studio的UI预览中,地图也没有覆盖整个屏幕

<LinearLayout xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<EditText
    android:layout_width="269dp"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/SearchLocationText"
    android:hint="Search Location"
    android:textCursorDrawable="@drawable/black_cursor"
    />

<Button
    android:text="Search"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/SearchButton"
    android:onClick="onSearch" />

</LinearLayout>

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    tools:context="com.anand.projectv10.MapsActivity1"
    android:layout_height="519dp"
    android:layout_width="382dp" />


您有一个android studio的设计预览。因此,您将设计一些东西来覆盖该屏幕,但请注意,每个屏幕的尺寸(宽度/高度/dpi)并不相同。当您使用核心值时,在实际场景中很有可能使视图位置出错。基于比率指定的值始终保持良好

您可以使用
weightSum
layout\u weight
来实现您想要的,而无需硬编码值

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="5">

            <EditText
                android:id="@+id/SearchLocationText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:ems="10"
                android:hint="Search Location"
                android:inputType="textPersonName"
                android:textCursorDrawable="@drawable/black_cursor" />

            <Button
                android:id="@+id/SearchButton"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="onSearch"
                android:text="Search" />

        </LinearLayout>

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.anand.projectv10.MapsActivity1" />

    </LinearLayout>

如需进一步了解,请阅读


你能发布屏幕截图吗?现在你想要实现什么?还要注意的是,您在视图中都给出了硬代码值,这样就可以实现!!例如:width=“269dp,height=“519dpI现在添加了一个屏幕截图。我已经给出了答案!