How to get my layout correct for inputting coordinates in EditTexts for Maps
-
27-09-2019 - |
문제
I need to input latitude and longitude separately in 2 EditText
s and display the location at the click of a button
. Somehow i'm not able to get the correct layout as i precisely require 2 EditText
s aligned side by side and a button
below them.
Here is what i already have:
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:text="@+id/EditText01"
android:layout_height="wrap_content"
android:id="@+id/edLat"
android:layout_toRightOf="@+id/mapView">
</EditText>
<EditText
android:layout_marginLeft="-237dip"
android:layout_marginTop="100dip"
android:layout_width="wrap_content"
android:text="@+id/EditText01"
android:layout_height="wrap_content"
android:id="@+id/edLong"
android:layout_toRightOf="@+id/mapView">
</EditText>
<Button
android:layout_marginLeft="-237dip"
android:layout_marginTop="200dip"
android:layout_width="wrap_content"
android:text="Show Location"
android:layout_height="wrap_content"
android:id="@+id/btnShowLoc"
android:layout_toRightOf="@+id/mapView"></Button>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg" />
</LinearLayout>
해결책
The below code suits your requirements:
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edLat">
</EditText>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edLong">
</EditText>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:text="Show Location"
android:layout_height="wrap_content"
android:id="@+id/btnShowLoc">
</Button>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg"
/>
</LinearLayout>
Note:
you have written the below kind of code:
<EditText android:layout_marginLeft="-237dip" android:layout_marginTop="100dip" android:layout_width="wrap_content" android:text="@+id/EditText01" android:layout_height="wrap_content" android:id="@+id/edLong" android:layout_toRightOf="@+id/mapView"></EditText>
I would like to tell you that don't give this kind of position to any control because in Android, there are different types of resolutions so it will not look the same design on every Android device.
After seeing your code, i can say you should learn Layouts and code techniques first. Refer Android-sdk pages.
Updated Answer with Images:<29-oct-2010>
I think you forgot to add <uses-library android:name="com.google.android.maps" />
permission in AndroidManifest.xml file, add this permission inside the <application>
tag.
Check out the below image, the same above code working for me:
다른 팁
I tried using a tabular layout here and works fine for my purpose. I'd appreciate if anyone can come up with a better layout and provide me with a valuable suggestion. Thanks
<EditText
android:id="@+id/edLat"
android:width="200px" />
</TableRow>
<TableRow>
<EditText
android:id="@+id/edLong"
/>
</TableRow>
<TableRow>
<Button
android:id="@+id/btnShowLoc"
android:layout_width="125px"
android:layout_height="wrap_content"
android:text="Show Location"
android:layout_below="@+id/txtComments"
android:layout_alignBottom="@+id/mapView"
/>
</TableRow>
<TableRow>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg"
/>
</TableRow>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</TableLayout>