Vertically Space “Weight” between Linear Layout Buttons -- [Question Asked]

Issue

enter image description here

I was wondering how to add space between buttons vertically, I was following instructor and the buttons on his screen seems good. Also, when I downloaded his project files the problem still facing me.

I am new to this weight technology in XML.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tvInput"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="#EFEFEF"
        android:textSize="48sp"
        android:maxLength="12"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <Button
            android:id="@+id/btnSeven"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="7"
            android:onClick="onDigit"
            />
        <Button
            android:id="@+id/btnEight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="8"
            android:onClick="onDigit"
            />
        <Button
            android:id="@+id/btnNine"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="9"
            android:onClick="onDigit"
            />
        <Button
            android:id="@+id/btnDivide"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="/"
            android:onClick="onDigit"
            />



    </LinearLayout>
      
</LinearLayout>

Answer we found from sources

you want to add margin between buttons in weighted view or any other type of view. The solution is you want to add the line which i have written below.


for horizontal margin

android:layout_marginHorizontal="5dp" 
<!--change the dp size prefered your design-->

for vertical margin

android:layout_marginVertical="5dp" 
<!--change the dp size prefered your design-->

or if you preferly want to set margin to left, top, right, bottom.


for left, top, right, bottom margin

<!--left-->
android:layout_marginLeft="5dp" 
<!--change the dp size prefered your design-->

<!--top-->
android:layout_marginTop="5dp" 
<!--change the dp size prefered your design-->

<!--right-->
android:layout_marginRight="5dp" 
<!--change the dp size prefered your design-->

<!--bottom-->
android:layout_marginBottom="5dp" 
<!--change the dp size prefered your design-->

if, I solved your problem please give tick mark & up-vote this answer. Thanks in advance. üòâ

Answered By – Pratik PSB

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0


What is Android?

Android OS is a Linux-based versatile working framework that fundamentally runs on cell phones and tablets.

Android was delivered under the Apache v2 open source permit; this takes into account numerous varieties of the OS to be created for different gadgets, like gaming consoles and advanced cameras. Android depends on open source programming, yet most Android gadgets come preinstalled with a set-up of restrictive programming, for example, Google Maps, YouTube, Google Chrome and Gmail.

The Android stage incorporates a working framework in view of the Linux piece, a GUI, an internet browser and end-client applications that can be downloaded. Albeit the underlying shows of Android included a nonexclusive QWERTY cell phone and enormous VGA screen, the working framework was composed to run on somewhat economical handsets with ordinary numeric keypads.
Who we are?

We are team of software engineers in multiple domains like Programming and coding, Fundamentals of computer science, Design and architecture, Algorithms and data structures, Information analysis, Debugging software and Testing software. We are working on Systems developer and application developer. We are curious, methodical, rational, analytical, and logical. Some of us are also conventional, meaning we're conscientious and conservative.

Answer collected from stackoverflow and other sources, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0