How to add space between two text fields

I'm new to android development and I'm just wondering how can I add space between two TextViews? Any help would be appreciated.

The code I wrote so far

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/lbl_group_coworkers" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Coworkers" /> <TextView android:id="@id/lbl_group_" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Family"/> </LinearLayout> 
+6
source share
9 answers

You can use android: layout_marginTop = "value" like this

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/lbl_group_coworkers" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Coworkers" /> <TextView android:id="@id/lbl_group_" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Family"/> </LinearLayout> 
+13
source

you may have a field between two text fields. add the top edge to the second texture

like this

  <TextView android:id="@id/lbl_group_" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="Family"/> 
+5
source

Just replace <LinearLayout> </LinearLayout> with <RelativeLayout> </RelativeLayout> then go to the graphical layout and adjust the space as you like.

+2
source

add mark left top right

  android:layout_marginLeft="10dp" 
+1
source

add android:layout_marginRight="..." to the first textView

+1
source

try adding margin

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/lbl_group_coworkers" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Coworkers" android:layout_margin="10dp"/> <TextView android:id="@+id/lbl_group" android:layout_margin="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Family"/> </LinearLayout> 
+1
source

you can use

android:layout_margin="5dp"

or

 android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" 

But before you ask much more such questions, I would advise reading the manuals for Android developers ( http://developer.android.com/guide/components/fundamentals.html )

Good luck and have fun developing ...

+1
source

You can use either the add-on or the margin depending on what you need, here is the link of the guy who gives a good explanation between them, which will help you decide which one you want to use: android brand and add-on

+1
source
  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/custom_border" > <TextView android:text="@string/textView_reference_number" style="@style/CustomTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView_refernce_number_label" /> <TextView android:text="Reference Number Value" style="@style/CustomTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView_refernce_number" android:layout_marginTop="10dp"/> </LinearLayout> 

android: layout_marginTop An XML attribute is used to indicate additional space at the top of this view. Thus, android: layout_marginTop = "10dp" on the second text screen indicates 10 dp of space between it and above it. @UDI See link below for more details on the same https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html

-1
source

Source: https://habr.com/ru/post/953622/


All Articles