Why margins with same properties show up differently?

Search This thread

BuderBrodas

New member
Oct 1, 2020
1
0
Hey, everyone
I'm a beginner trying to make my first app (a calculator) look fancier.
I've started with by adding colors to the buttons. Quickly I've noticed that by adding color to a button's background it looses its border with another button. So I've tried to use margins. Everything went great until I had to deal with the last LinearLayout, last line of the calculator buttons. It's different than the previous LinearLayouts and I guess the picture describes it well enough:

Turns out I cannot post the picture, so I'll try to describe it as detailed as possible: the thing is that my 3rd row includes 4 buttons(1, 2 ,3 and -) and so does the 4th, but there 2 out of 4 buttons are split vertically and I guess because of that the margins of the forth row do not allign with the ones from the 3rd even though their properties are the same (android:layout_marginVertical="3dp" and android:layout_marginHorizontal="5dp")


The buttons of the 3rd row do not allign with the ones from 4th

I've tried to manually make margins( to the left and right insted of "Horzontal"), however that does not seem to be a proper soliution, or maybe I'm just missing something

my code for the 4th row :
HTML:
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

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

            <Button
                android:id="@+id/dot"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_marginVertical="3dp"
                android:layout_marginHorizontal="5dp"
                android:background="#D79E2D"
                android:gravity="top|center"
                android:text="."
                android:textSize="30sp" />

            <Button
                android:id="@+id/equals"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_marginVertical="3dp"
                android:layout_marginHorizontal="5dp"
                android:background="#D79E2D"
                android:text="="
                android:textSize="40sp" />


        </LinearLayout>

        <Button
            android:background="#D79E2D"
            android:id="@+id/n0"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginVertical="3dp"
            android:layout_marginHorizontal="5dp"
            android:text="0"
            android:textSize="25sp" />

        <LinearLayout

            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_marginVertical="3dp"
            android:layout_marginHorizontal="5dp"
            android:orientation="vertical">

            <Button
                android:background="#D79E2D"
                android:id="@+id/changeSign"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_marginVertical="3dp"
                android:layout_marginHorizontal="5dp"
                android:text="+/-"
                android:textSize="30dp"
                />

            <Button
                android:background="#D79E2D"

                android:id="@+id/Back"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_marginVertical="3dp"
                android:layout_marginHorizontal="5dp"
                android:text="Del"
                android:textSize="30sp"
                android:gravity="top|center"
                />


        </LinearLayout>

        <Button
            android:id="@+id/plus"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#D79E2D"
            android:layout_marginVertical="3dp"
            android:layout_marginHorizontal="5dp"
            android:text="+"
            android:textSize="25sp" />


    </LinearLayout>

If you have an idea how to overcome this, please let me know. I'd really appreciate it.
 
Last edited: