【问题标题】:Android/Java - Margin on left/right/bottomAndroid/Java - 左/右/下边距
【发布时间】:2017-11-21 09:05:21
【问题描述】:

如何从按钮中删除这些边距?

https://i.stack.imgur.com/UBPhR.png

我想要 100% 宽度的按钮:/

我的活动 xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
tools:context="${relativePackage}.${activityClass}" >

<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="34dp"
    android:backgroundTint="#1379ff" />

<Button
    android:id="@+id/Button01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:backgroundTint="#313131" />

    android:layout_alignParentLeft="true"
    android:layout_weight="1"
    android:text="Button" />

【问题讨论】:

  • 发布您的代码?
  • 在您的布局中,您可能指定了默认边距删除它们
  • 能否请您也发布您的xml
  • 我已将我的 xml 添加到帖子中
  • 你的代码完整吗?

标签: java android xml button margin


【解决方案1】:

在你的RelativeLayout 中你应该使用fill_parent 也许是因为它的 父宽度

【讨论】:

    【解决方案2】:
    Use negative margin to the parent layout like below.
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="-5dp"
    android:layout_marginRight="-5dp"
    
     >
    
    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="34dp"
        android:backgroundTint="#1379ff" />
    
    <Button
        android:id="@+id/Button01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:backgroundTint="#313131" />
    

    【讨论】:

      猜你喜欢
      • 2017-03-11
      • 2016-12-07
      • 2015-05-11
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 2020-09-22
      • 2015-02-15
      • 1970-01-01
      相关资源
      最近更新 更多