Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Position Relative layout within main layout Dynamicaly
    primarykey
    data
    text
    <p>I am trying to add Relative Layout to my mainLayout (which is also a relative layout) dynamically. I have it so that you can add the layout multiple times by clicking a button. But I want it so that the first layout added is on the leftside of the screen, the second layout is in the middle and the thirs layout is on the right, etc... I did this using the modulus operator but it isnt working. </p> <p>Below is my code</p> <pre><code>LinearLayout mLinearLayout; RelativeLayout rlcopy; RelativeLayout[] rArray = new RelativeLayout[20]; int counter = 1; RelativeLayout llcustomrow; RelativeLayout.LayoutParams relativeLayoutParams; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mLinearLayout = (LinearLayout) inflater.inflate( R.layout.customworkout, container, false); llcustomrow = (RelativeLayout)mLinearLayout.findViewById(R.id.llcustomrow); for(int i = 1;i&lt;rArray.length-1;i++){ rArray[i] = (RelativeLayout)View.inflate(getActivity(), R.layout.addworkoutlayout, null); if(i%3 == 1 ){ rArray[i].setGravity(Gravity.LEFT); }else if(i%3 == 2){ rArray[i].setGravity(Gravity.CENTER_HORIZONTAL); }else{ rArray[i].setGravity(Gravity.RIGHT); } } Button bAdd = (Button) mLinearLayout.findViewById(R.id.bAddExcercise); bAdd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { llcustomrow.addView(rArray[counter]); counter++; } }); return mLinearLayout; } </code></pre> <p>I believe the problem is where i am setting the gravity, I do not think it is doing anything</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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