2011-01-16 2 views
2

Я пытаюсь показать макет как изображение 1 (textView и editText в той же строке), но мой внешний вид показан как изображение 2! я стараюсь с этим кодом:проблема с макетами в android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="5px" 
    > 

    <TextView 
     android:id="@+id/label" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="URL:" 
     android:layout_alignBaseline="@+id/entry" 
     android:layout_alignParentLeft="true"/> 
     /> 

    <EditText 
     android:id="@+id/entry" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/label" 
     android:layout_alignParentTop="true" 
     /> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:paddingRight="30px" 
     android:paddingLeft="30px" 
     android:text="Go..." 
     /> 

</LinearLayout> 

пожалуйста, помогите мне спасибо

image1

image2

ответ

4

Попробуйте

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
<TextView 
    android:id="@+id/label" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="URL:" 
    android:layout_alignBaseline="@+id/entry" 
    android:layout_alignParentLeft="true"/> 
    /> 
<EditText 
    android:id="@+id/entry" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/label" 
    android:layout_alignParentTop="true" 
    /> 
</LinearLayout> 
<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:paddingRight="30px" 
    android:paddingLeft="30px" 
    android:text="Go..." 
    /> 
</LinearLayout> 

Или использовать RelativeLayout

1

Насколько я понял, вы не можете использовать такие атрибуты _toRightTop, _BOTTOM с линейным макетом. Используйте RelativeLayout, и все должно быть хорошо.

1

Используйте относительную компоновку вместо линейной компоновки. Одно из преимуществ этого заключается в том, что она улучшает вашу производительность. Если вы пытаетесь выполнить поиск и удостоверяете личность линейного макета, он будет проверять каждый компонент линейного макета и попытаться соответствовать его идентификатор, но с компоновкой релятивиста он будет быстрее, поскольку все элементы определены относительно друг друга.

Смежные вопросы