Note that there are some explanatory texts on larger screens.

plurals
  1. POSetMargin Programatically not working correctly for RelativeLayoutParams
    primarykey
    data
    text
    <p>I'm currently Programatically adding RelativeLayout encapsulated in a Linearlayout. The base is a scrollview and i'm trying to add those layouts into scrollview named svbase </p> <pre><code>LinearLayout llbase = new LinearLayout(getApplicationContext()); LinearLayout.LayoutParams llbaseParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); // Verbose! llbaseParams.setMargins(0, new CommonOpearation().getPixel(10, getApplicationContext()), 0, new CommonOpearation().getPixel(10, getApplicationContext())); llbase.setLayoutParams(llbaseParams); llbase.setGravity(Gravity.CENTER_HORIZONTAL); for(int n =0;n&lt;2;n++) { RelativeLayout rLayoutBase = new RelativeLayout(getApplicationContext()); RelativeLayout.LayoutParams rLayoutParms = new RelativeLayout.LayoutParams( new CommonOpearation().getPixel(140, getApplicationContext()), new CommonOpearation().getPixel(125, getApplicationContext())); **rLayoutParms.setMargins(0, 0, new CommonOpearation().getPixel(5, getApplicationContext()), 0);** rLayoutBase.setLayoutParams(rLayoutParms); Drawable drawable = MyCurrentActivity.this.getApplicationContext().getResources().getDrawable(R.drawable.curved_bg); //new Image that was added to the res folder try { rLayoutBase.getClass().getMethod(android.os.Build.VERSION.SDK_INT &gt;= 16 ? "setBackground" : "setBackgroundDrawable", Drawable.class).invoke(rLayoutBase, drawable); } catch (Exception ex) { } llbase.addView(rLayoutBase); } svBase.addView(llbase); </code></pre> <p>As you can see i have two relativelayout encapsulated in the linearlayout with a horizontal orientation. I've tried giving margin to each of the relativelayout using setMargin with a right of certain 5dp. However it does not gives margin inbetween the two relativelayout. It worked if i were to do in manually in xml though. </p> <p>The differences can be seen at the image. the top is a xml specify layout while the bottom two relativelayout are generated programatically </p> <p><img src="https://i.stack.imgur.com/EsgL1.png" alt="enter image description here"></p>
    singulars
    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