Issue
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