2013-02-15 37 views
10

Tôi có 3 nút Layout.xml bên dưới nơi họ xuất hiện bên dưới của nhau ...tuyến tính diện với hai nút cạnh nhau - android

   <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:padding="10dip" > 

        <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 

        <Button 
         android:id="@+id/btn_1" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Car" /> 

        <Button 
         android:id="@+id/btn_2" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="Vehicle" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" > 

        <Button 
         android:id="@+id/btn_3" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Bike" /> 
       </LinearLayout> 
      </LinearLayout> 

Tôi muốn có hai nút phía trước bởi bên (btn_1 và btn_2). Ai có thể cho tôi một gợi ý về làm thế nào để làm điều đó?

Thanks a lot

+0

được trường hợp tương tự: http://stackoverflow.com/questions/5551349/2-buttons-side-by-side-android-layouts/21411490#21411490 – iarroyo

Trả lời

16

chỉ cần thay đổi android:orientation="vertical"-android:orientation="horizontal" của bố trí của bạn và tất cả mọi thứ sẽ hoạt động tốt

3

Thay đổi Linear Layout định hướng theo chiều dọc vào Horizontal.And sau đó cho trọng lượng cho cả hai nút của bạn như là 1 hoặc 2 Như bạn muốn.the nút sẽ được sắp xếp như nhau.

7

Cách tốt nhất để làm điều này là để làm cho bố trí và sau đó đặt nút của bạn như mã này

<TableRow 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<Button 
    android:id="@+id/Button9" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:text="@string/Home1"/> 

<Button 
    android:id="@+id/Button11" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right"  
    android:text="@string/NextL"/> 

trong tình trạng này, bạn có hai nút trong cùng một hàng dễ dàng như vậy: D

+0

Có vẻ như bạn forgor là một thẻ đóng? Ngoài ra, "Một TableRow nên luôn luôn được sử dụng như một đứa trẻ của một TableLayout", theo [docs] (http://developer.android.com/reference/android/widget/TableRow.html). – dst

+0

Tôi đã quên những thứ đó và không có nghĩa vụ nào có thể được sử dụng trong hầu hết các bố trí, tôi đã sử dụng chúng bên trong LinearLayout và làm việc ra – user3287335

+0

đó là lý do tại sao tài liệu chỉ đề cập * nên * chứ không phải * phải *. Nhưng như các tài liệu đề nghị chống lại nó, tôi sẽ không khuyên bạn nên nó hoặc trong trường hợp phiên bản Android mới phá vỡ một cái gì đó ở đó. – dst

Các vấn đề liên quan