【问题标题】:Getting rid of space between Buttons in Linear Layout消除线性布局中按钮之间的空间
【发布时间】:2017-03-25 09:46:23
【问题描述】:

我无法减少线性布局中 2 个按钮之间的间距。 我尝试了很多组合,但都没有成功。

这是我的 XML sn-p:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="100dp"
    android:id="@+id/linSocial">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/facebook"
        android:id="@+id/btFacebook"
        android:visibility="gone" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/gmaillogo"
        android:id="@+id/btGmail"
        android:layout_marginTop="1dp"
        android:visibility="gone"/>

</LinearLayout>

【问题讨论】:

  • 你检查过android:layout_marginBottom="100dp"这行吗?这可能是您所说的空间。
  • 您好,感谢您的意见。虽然其他东西解决了问题 .android:layout_marginTop="-60dp" 在第二个按钮:D
  • 确保您的btFacebook 没有内部间距。
  • 您尝试了哪些组合?您能否发布当前布局的屏幕截图并说明您想要与众不同的地方?

标签: android android-linearlayout android-button


【解决方案1】:

试试这个

 <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linSocial">
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/facebook"
    android:id="@+id/btFacebook"
    android:visibility="gone" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/gmaillogo"
    android:id="@+id/btGmail"
    android:layout_marginTop="5dp"
    android:visibility="gone"/>

【讨论】: