title: Set margins from textviews programmatically
body: <p>Im trying to make a view where there is a static margin between textviews that i have made programmatically, how can i make this happened? I tried alot and my</p>
  
  <pre><code>setMargins(viewEvent, 20, placeSum, 0, 0);
  </code></pre>
  
  <p>just setting margins top from the layout and as said i want to make margins to the above textview.</p>
  
  <p>Here is my loop</p>
  
  <pre><code>int set=0;
          for (int i = 0; i &lt; partEvents.length; i++) {
              RelativeLayout relativeLayout = (RelativeLayout) eventView.findViewById(R.id.eventRelativeLayout);
              TextView viewEvent = new TextView(getActivity());
              viewEvent.setBackgroundResource(R.drawable.eventbg);
  
              viewEvent.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
                      RelativeLayout.LayoutParams.WRAP_CONTENT));
  
  
  
              String startHour = getHourFromString(partEvents[i][2]);
              String startMinute = getMinuteFromString(partEvents[i][2]);
              String endHour = getHourFromString(partEvents[i][3]);
              String endMinute = getMinuteFromString(partEvents[i][3]);
  
              viewEvent.setText(partEvents[i][0]+ "\n" +
              partEvents[i][1] + "\n"
              + startHour + ":" + startMinute + "-" + endHour + ":" + endMinute  );
  
  
              final float scale = getResources().getDisplayMetrics().density;
              int placeSum = (int) (10 + set * scale + 0.5f);
              setMargins(viewEvent, 20, placeSum, 0, 0);
  
  
              viewEvent.setTextSize(20);
  
  
  
              set=set+100;
              try {
                  relativeLayout.addView(viewEvent);
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
  </code></pre>
  
  <p>xml</p>
  
  <p>&lt;</p>
  
  <pre><code>?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/relativeLayout"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:layout_below="@+id/dividerView"
      android:layout_alignParentBottom="true"&gt;
  
  &lt;LinearLayout
      android:id="@+id/temp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;RelativeLayout
          android:layout_width="0dp"
          android:layout_height="200dp"
          android:layout_weight="1" &gt;
  
          &lt;TextView
      android:text="Event namn:"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView"
      android:layout_alignParentTop="true"
      android:layout_alignParentStart="true"
      android:layout_marginTop="12dp" /&gt;
  
  &lt;TextView
      android:text="TextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="22dp"
      android:id="@+id/sum"
      android:gravity="center_vertical"
      android:textStyle="normal|bold"
      android:textSize="20sp"
      android:layout_alignTop="@+id/textView"
      android:layout_alignParentStart="true" /&gt;
  
  &lt;TextView
      android:text="Beskrivning:"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView4"
      android:layout_below="@+id/sum"
      android:layout_alignParentStart="true"
      android:layout_marginTop="20dp" /&gt;
  
  &lt;TextView
      android:text="TextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="23dp"
      android:gravity="center_vertical"
      android:id="@+id/description"
      android:textStyle="normal|bold"
      android:textSize="20sp"
      android:layout_alignTop="@+id/textView4"
      android:layout_alignParentStart="true" /&gt;
  
  &lt;TextView
      android:text="TextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:gravity="center_vertical"
      android:layout_marginTop="21dp"
      android:id="@+id/startEvent"
      android:textStyle="normal|bold"
      android:textSize="20sp"
      android:layout_alignTop="@+id/textView5"
      android:layout_alignParentStart="true" /&gt;
  
  &lt;TextView
      android:text="Tider:"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView5"
      android:layout_marginTop="14dp"
      android:layout_below="@+id/description"
      android:layout_alignParentStart="true" /&gt;
  
          &lt;TextView
              android:text="Time"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentTop="true"
              android:layout_alignParentEnd="true"
              android:layout_marginEnd="13dp"
              android:layout_marginTop="10dp"
              android:id="@+id/time"
              android:textSize="25sp"
              android:layout_marginLeft="0dp" /&gt;
  
      &lt;/RelativeLayout&gt;
  &lt;/LinearLayout&gt;
      &lt;View
          android:id="@+id/dividerView"
          android:layout_width="fill_parent"
          android:layout_height="1dp"
          android:layout_below="@+id/temp"
          android:background="@color/colorPrimary" /&gt;
  
  
  &lt;ScrollView
      android:id="@+id/eventScrollView"
      android:layout_width="match_parent"
      android:overScrollMode="never"
      android:layout_below="@+id/dividerView"
      android:padding="0dp"
      android:scrollbars="none"
      android:fadingEdge="none"
      android:layout_height="fill_parent"&gt;
  
  &lt;RelativeLayout
      android:id="@+id/eventRelativeLayout"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:minHeight="510dp"&gt;
  
  
      &lt;/RelativeLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>