Note that there are some explanatory texts on larger screens.

plurals
  1. POControls overlap when trying to position programmatically using relative layout (Android)
    primarykey
    data
    text
    <p>I am trying to create a fragment. In the fragment I plan to place a text view next to it a Spinner control. I tried using this code. However Spinner always is placed over textview to the left of the screen. Can anyone suggest what could be the problem?</p> <p>Code:</p> <pre><code>public class FragmentTest extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RelativeLayout view = (RelativeLayout)inflater.inflate(R.layout.ll2, null); RelativeLayout lref = (RelativeLayout)view.findViewById(R.id.ll2ll); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(lref.getLayoutParams()); lp.addRule(RelativeLayout.ALIGN_LEFT); RelativeLayout rl = new RelativeLayout(getActivity()); TextView tv = new TextView(getActivity()); tv.setId(1); tv.setLayoutParams(lp); tv.setText("My "); rl.addView(tv, lp); Spinner s = new Spinner(getActivity()); lp.addRule(RelativeLayout.RIGHT_OF, tv.getId()); s.setId(2); String currencyData[] = {"USD", "EUR","INR" }; ArrayAdapter&lt;Object&gt; currencyAdapter; currencyAdapter = new ArrayAdapter&lt;Object&gt;(getActivity(), android.R.layout.simple_spinner_item, currencyData); currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s.setAdapter(currencyAdapter); rl.addView(s,lp); return rl; } } </code></pre> <p>XML file is</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp" android:layout_height="fill_parent" android:layout_marginLeft="10sp" android:layout_marginRight="10sp" android:layout_marginTop="10sp" android:isScrollContainer="true" android:orientation="horizontal" &gt; &lt;RelativeLayout android:id="@+id/ll2ll" android:layout_width="140dp" android:layout_height="50dp" android:textSize="@dimen/font_size" /&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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