Android Studio:内容关闭屏幕

时间:2017-01-28 04:14:44

标签: android-layout android-studio

当我安装在实际的Android设备上时,我的部分UI会在屏幕外显示。它使用Google maps 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" />

1 个答案:

答案 0 :(得分:1)

你预览了你在android studio设计的东西。所以你会设计一些东西来覆盖那个屏幕,但请注意每个屏幕都没有相同的尺寸(宽度/高度/ dpi)。当您硬核值时,很有可能在实际场景中使视图位置出错。基于比率分配的值总是很好。

您可以使用weightSumlayout_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>

进一步了解阅读 What is android:weightSum in android, and how does it work?

What does android:layout_weight mean?

相关问题