Как получить мой макет правильно для ввода координат в Edittexts для карт

StackOverflow https://stackoverflow.com/questions/4040684

Вопрос

Мне нужно вводить широту и долготу отдельно в 2 EditTexts и отобразить местоположение на клик button. Отказ Каким-то образом я не могу получить правильный макет, так как именно требовался 2 EditTexts выровнен стороной рядом и button ниже них.

Вот то, что у меня уже есть:

    <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>
Это было полезно?

Решение

Нижний код соответствует вашим требованиям:

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

Примечание:

Вы написали следующий вид кода:

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

Я хотел бы сказать вам, что не дайте такого рода позиции любому контролю, потому что в Android есть разные типы разрешений, поэтому он не будет выглядеть та же дизайн на каждом устройстве Android.

После просмотра вашего кода я могу сказать, что вы должны сначала изучать макеты и методы кода. См. Страницы Android-SDK.

Обновленный ответ с изображениями: <29-окт-окт-2010>


Я думаю, что вы забыли добавить <uses-library android:name="com.google.android.maps" /> Разрешение в файле androidmanifest.xml, добавьте это разрешение внутри <application> ярлык.

Проверьте изображение ниже, тот же самый код, работающий для меня:

alt text

Другие советы

Я пытался использовать табличную макет здесь и отлично работает для моей цели. Я был бы признателен, если кто-нибудь сможет придумать лучшую макет и предоставить мне ценное предложение. Спасибо

        <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>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top