-1

Part of my UI goes off-screen when installed on an actual android device. It uses the Google maps API. The "my location" button goes a little bit off screen.

Also the map doesn't cover the complete screen even though it does in the UI preview in Android Studio.

<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 Answers1

1

You have a preview of what you are designing at android studio.So you will design something to cover that screen but note that every screen is not with the same dimensions(width/height/dpi). When you hardcore values there is a high possibility to make view positions go wrong in real scenarios.Values assigned based on ratios always stick fine.

You can use weightSum and layout_weight to achieve what you want without hard coding values

<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>

For further understanding Read What is android:weightSum in android, and how does it work?

What does android:layout_weight mean?

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88