0

layout.xml 代码部分:

<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代码部分:

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

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

2 回答 2

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

您可以使用RelativeLayout./insert static constant/addRule

于 2013-10-31T19:32:31.960 回答
1

尝试这个:

 LayoutParams lp= (LayoutParams) list.getLayoutParams();
 lp.setMargins(left, top, right, bottom);
 list.setLayoutParams(lp);
于 2013-10-31T19:42:57.000 回答