Reputation: 77984
friends,
i want to set layout_marginBottom using java code or dynamically
in list view or linearlayout
any one guide me how to achieve this?
any help would be appreciated.
Upvotes: 2
Views: 9853
Reputation: 1563
to change margin dynamically using the animation:
Animation animMarginChange = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mListView
.getLayoutParams();
layoutParams.setMargins(100, 0, 0, 0);
}
};
animMarginChange.setDuration(500); // in ms
mListView.startAnimation(animMarginChange);
Upvotes: 0
Reputation: 3155
For ListView, there is much more simpler method to change margin by Programmatically
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mListView
.getLayoutParams();
layoutParams.setMargins(0, 0, 0, 0);
But for LinearLayout, you can set margin from @UMAR answer. Have fun. @.@
Upvotes: 3
Reputation: 77984
ListView lst=getListView();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT
);
params.setMargins(0, 0, 0, 0); //left,top,right,bottom
lst.setLayoutParams(params);
Upvotes: 8