2011-08-23 36 views

Trả lời

16

này cung cấp cho một shot:

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <EditText android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
    <EditText android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
</LinearLayout> 

Ngoài ra, bạn nên cố gắng chấp nhận câu trả lời nếu bạn nhận được một trong những câu trả lời câu hỏi của bạn. Bạn sẽ có nhiều khả năng nhận được nhiều phản hồi tốt hơn.

5

Có nhiều cách, sau đây là 2.

Với một LinearLayout ngang

Gán android:orientation="horizontal" để bên ngoài của bạn LinearLayout. Bằng cách này, tất cả các phần tử con của bố cục này sẽ được căn chỉnh bên cạnh nhau.

Semi-layout:

<LinearLayout android:orientation="horizontal"> 
    <EditText /> 
    <EditText /> 
</LinearLayout> 

Với RelativeLayout

Sử dụng android:layout_toLeftOf="@id/otheredittext" hoặc android:layout_toRightOf="@id/.." nói với một trong những EditTexts rằng nó thuộc về quyền/bên trái của người kia và sắp xếp người đầu tiên liên quan đến cha mẹ (số RelativeLayout) bằng cách sử dụng android:layout_alignParentTop="true", cùng với trái, phải hoặc dưới cùng.

Semi-layout:

<RelativeLayout> 
    <EditText android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:id="@+id/edittext1" 
       /> 
    <EditText android:layout_toRightOf="@id/edittext1" /> 
</RelativeLayout> 

(Cũng cần lưu ý rằng bạn có một +id khi gán id cho lần đầu tiên trong android:id và khi bạn tham khảo nó từ cách bố trí thông qua android:layout_to..., nó chỉ là id)

1

Đối với bố cục tuyến tính, nó sẽ như sau:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"> 
<EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="100dip"> 
    <requestFocus></requestFocus> 
</EditText> 
<EditText android:layout_height="wrap_content" android:id="@+id/editText2" android:layout_width="100dip"></EditText> 
</LinearLayout> 

Đối với cách bố trí tương đối nó sẽ được như sau:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="100dip"> 
    <requestFocus></requestFocus> 
</EditText> 
<EditText android:layout_height="wrap_content" android:layout_width="100dip" android:id="@+id/editText2" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></EditText> 
</RelativeLayout> 
Các vấn đề liên quan