2011-10-21 19 views
5

Tôi gặp sự cố khi thiết kế menu của ứng dụng có XML. Điều tôi muốn làm là có cả hai số ToggleButtonButton ở cùng độ cao, nhưng Button không xuất hiện căn chỉnh. Nó giống như nó có thứ gì đó ẩn bên dưới nó khiến nó xuất hiện cao hơn một chút.Nút và ToggleButton sẽ không căn chỉnh ở cùng độ cao

Tôi đã tìm kiếm thông tin, nhưng tôi thấy không có gì

Dưới đây là đoạn code tôi viết trên main.xml:

(...)  
    <TextView 
     android:text="Option1:" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <ToggleButton 
     android:id="@+id/toggle_option1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:width="100sp" 
     android:height="50sp" /> 
    <Button 
     android:id="@+id/button_option1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:height="50sp" 
     android:text="See" 
    /> 
    </LinearLayout> 

Bất cứ ý tưởng?

+1

Ông có thể vui lòng cung cấp cho chúng ta một ảnh chụp màn hình? Chỉ cần đăng URL hình ảnh trong câu hỏi và tôi sẽ đăng hình ảnh. –

+0

thay đổi chiều cao của 'ToggleButton' là' android: layout_height = "fill_parent" ' –

+1

Cảm ơn bạn Adil Soomro, việc thay đổi thành fill_parent hoạt động tốt! – ArcDare

Trả lời

4

Hãy thử điều này:

<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 
<ToggleButton 
    android:id="@+id/toggle_option1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:width="100sp" 
    android:height="50sp" 
    android:layout_marginBottom="5sp" /> 
<Button 
    android:id="@+id/button_option1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:height="50sp" 
    android:text="See" 
    android:layout_marginTop="6sp" 
/> 
</LinearLayout> 
+2

Cảm ơn bạn rất nhiều! Với layout_margins Carnal Suggested nó hoạt động hoàn hảo! Nó không phải là lạ mà họ không phù hợp theo mặc định? PS: Tôi muốn bỏ phiếu, nhưng tôi không thể vì tôi vẫn dưới 15 tuổi danh tiếng. Tôi sẽ làm điều đó khi tôi có thể! – ArcDare

+0

Đó là bạn đời, nhưng có một cách dễ dàng hơn. Thay vì sử dụng android: layout_marginBottom và marginTop, hãy thử sử dụng android: layout_height = "fill_parent" trên nút toggle, xem nó có hoạt động hay không :) – Carnal

+1

. Tôi nghĩ đó là cách tốt nhất! – ArcDare

0
<ToggleButton 
android:layout_height="wrap_content" 
android:id="@+id/toggle_option1" 
android:layout_width="70dp"> 
</ToggleButton> 
    <Button 
android:id="@+id/button_option1" 
android:text="See" 
android:layout_height="wrap_content" 
android:layout_width="70dp"> 
</Button> 
+0

Tôi xin lỗi nhưng điều đó không thực sự làm những gì chúng tôi đang tìm kiếm ngay cả khi tôi thêm Bố cục tuyến tính ngang; Nút vẫn không liên kết với nút gạt – ArcDare

2

Đây là những gì tôi đã làm:

<ToggleButton 
     android:id="@+id/tbtnAll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:height="48dp" 
     /> 

<Button 
     android:id="@+id/tbtnOther" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:height="50dp" 
    /> 
Các vấn đề liên quan