0

layout.xml code part:

<ListView
    android:id="@+android:id/listWhatever"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/rlSomething" 
    android:layout_marginBottom="I need this to set in code dinamically!"/>

Java code part:

listWhatever = (ListView)findViewById(R.id.listWhatever);
RelativeLayout.LayoutParams layoutParams = (LayoutParams) listWhatever.getLayoutParams();

layoutParams.addRule(android:layout_marginBottom ... , how?);

2 Answers 2

6
layoutParams.bottomMargin=0;//your bottom margin value
listWhatever.setLayoutParams(layoutParams);

You can use RelativeLayout./insert static constant/ with addRule

2
  • It should work. Maybe is it padding you are looking for? listWhatever.setPadding(left, top, right, bottom); (Can't see your comment anymore, but I won't delete this :) )
    – Sipka
    Oct 31, 2013 at 19:38
  • it will be accepted, since is working, needed a rebuild, but need to wait 5 min, because of SO stupid rules "You can accept an answer in 4 minutes"
    – user529543
    Oct 31, 2013 at 19:38
1

Try this:

 LayoutParams lp= (LayoutParams) list.getLayoutParams();
 lp.setMargins(left, top, right, bottom);
 list.setLayoutParams(lp);
1
  • that is not equivalent with android:layout_marginBottom, but be happy: +1
    – user529543
    Oct 31, 2013 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.