Android 布局\u边距而不是单独的边距不适用于负值

Android 布局\u边距而不是单独的边距不适用于负值,android,android-layout,Android,Android Layout,我想在我的项目中使用负值作为保证金。我发现它与我的目的相匹配,0dp的价值边际仍然太大。但由于某些原因,标签的总体布局不起作用 这是main.xml,带有说明问题的原始示例: <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/main" android:orientation="horizontal" android:layout_width="fill_p

我想在我的项目中使用负值作为保证金。我发现它与我的目的相匹配,0dp的价值边际仍然太大。但由于某些原因,标签的总体布局不起作用

这是main.xml,带有说明问题的原始示例:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
     android:id="@+id/main"
     android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout

        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent">

        <Button
           android:layout_margin="@dimen/default_button_margin"
           android:layout_width="match_parent"
           android:layout_height="0dp"
           android:layout_weight="1"
           android:text="New Button"
           android:id="@+id/button1"/>
        <Button
          android:layout_marginLeft="@dimen/default_button_margin"
          android:layout_marginRight="@dimen/default_button_margin"
          android:layout_marginBottom="@dimen/default_button_margin"
          android:layout_marginTop="@dimen/default_button_margin"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:text="New Button"
          android:id="@+id/button2"/>
    </LinearLayout>
    <LinearLayout
          android:orientation="vertical"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:layout_height="match_parent">

        <Button
            android:layout_marginLeft="@dimen/default_button_margin"
            android:layout_marginRight="@dimen/default_button_margin"
            android:layout_marginBottom="@dimen/default_button_margin"
            android:layout_marginTop="@dimen/default_button_margin"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="New Button"
            android:id="@+id/button3"/>
        <Button
            android:layout_marginLeft="@dimen/default_button_margin"
            android:layout_marginRight="@dimen/default_button_margin"
            android:layout_marginBottom="@dimen/default_button_margin"
            android:layout_marginTop="@dimen/default_button_margin"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="New Button"
           android:id="@+id/button4"/>
    </LinearLayout>
</LinearLayout>
不带导入语句的MainActivity.java:

和dimens.xml:


不幸的是,由于声誉问题,我无法发布图片。

您可以在此处链接您的图片,并让他人将其添加到您的帖子中。无论如何,我怀疑你能在Android中使用负边际。你到底想做什么?你想在你的场景中实现什么?是的,我们可以在android系统中提供负利润。我想制作带有方形字段的应用程序,使用许多方形按钮,如tic tac toe和sudoku等。在这种情况下,我想实现按钮之间的最小间距。无法链接图片,因为我的声誉太低了。
 public class MainActivity extends Activity {
    private final int FIELD_SIZE = 3;
    //private LinearLayout mainLayout = new LinearLayout(this);
    private Collection<LinearLayout> layouts = new LinkedList<>();
    private final Button[][] buttons = new Button[FIELD_SIZE][FIELD_SIZE];


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <dimen name="default_button_margin">-3dp</dimen>
    </resources>