Note that there are some explanatory texts on larger screens.

plurals
  1. POTextview not getting displayed to rightOf another textView programatically in android
    text
    copied!<p>I am trying to add textview dynamically to the right of the textView , but textView is not getting displayed.</p> <p>The statement "<strong>params2.addRule(RelativeLayout.RIGHT_OF, 1);"</strong> in the below code is creating a problem if i remove that line the textview is getting displayed at random position.</p> <p>Need to implement this xml dynamically </p> <pre><code>&lt;TextView android:id="@+id/stationnameVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="KANYAKUMARI (CAPE)" android:textColor="@color/black" android:textSize="12sp" /&gt; &lt;TextView android:id="@+id/arrivaltimeVal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="45dp" android:layout_toRightOf="@+id/stationnameVal" android:text="SRC" android:textColor="@color/black" android:textSize="12sp" /&gt; </code></pre> <p>Code is :</p> <pre><code> RelativeLayout rel = new RelativeLayout(this); // first TextView RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); TextView stateName = new TextView(DisplayActivity.this); stateName.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); params.setMargins(0, 5, 0, 0); stateName.setText("KANYAKUMARI (CAPE)"); stateName.setId(1); stateName.setTextColor(R.color.black); stateName.setTextSize(12); rel.addView(stateName, params); // Adding Second TextView RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); TextView arr = new TextView(DisplayActivity.this); arr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); arr.setText("SRC"); arr.setTextColor(R.color.white); arr.setTextSize(12); params2.addRule(RelativeLayout.ALIGN_PARENT_TOP, stateName.getId()); params2.addRule(RelativeLayout.RIGHT_OF, 1); params2.setMargins(45, 0, 0, 0); rel.addView(arr, params2); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload