Button和ToggleButton不会在同一高度对齐

Arc*_*are 5 android button android-layout

我在使用XML设计应用程序菜单时遇到了麻烦.我想要做的是有两个ToggleButton,并Button在相同的高度,但Button不会出现对齐.就好像它下面有一些看不见的东西让它看起来更高一点.

我一直在寻找信息,但我一无所获

这是我在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>
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Car*_*nal 4

尝试这个:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢!使用layout_margins Carnal建议它效果完美!默认情况下它们没有对齐,这不是很奇怪吗?PS:我会投票,但我不能,因为我的声誉仍然低于 15。当我有能力的时候我会做的! (2认同)